love fish大鹏一曰同风起,扶摇直上九万里

常用链接

统计

积分与排名

friends

link

最新评论

Webtop 6.5 DateTime控件选择日期时,星期几显示不全

处理前上期显示样式


处理后日期显示样式




package com.documentum.web.form.control;

import java.awt.Dimension;
import java.io.IOException;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;

import javax.servlet.jsp.JspWriter;

import com.documentum.fc.common.DfTime;
import com.documentum.web.common.AccessibilityService;
import com.documentum.web.common.BrandingService;
import com.documentum.web.common.IThemeResolver;
import com.documentum.web.common.ImageService;
import com.documentum.web.common.LocaleService;
import com.documentum.web.common.WrapperRuntimeException;
import com.documentum.web.form.Control;
import com.documentum.web.form.Form;
import com.documentum.web.util.DateUtil;
import com.documentum.web.util.SafeHTMLString;
import com.documentum.web.util.StringUtil;

/**
 * 
@author liaojiyong
 * @date Aug 2, 2009
 * 
@version 1.0
 
*/

public class DateTimeTag extends DateInputTag {

    
public DateTimeTag() {
        m_strHour 
= null;
        m_strMinute 
= null;
        m_strSecond 
= null;
        m_strTimeSelector 
= null;
        m_strTimeFormat 
= null;
        m_strTimeStep 
= null;
        m_strFromTime 
= null;
        m_strToTime 
= null;
    }


    
public void release() {
        
super.release();
        m_strHour 
= null;
        m_strMinute 
= null;
        m_strSecond 
= null;
        m_strTimeSelector 
= null;
        m_strTimeFormat 
= null;
        m_strTimeStep 
= null;
        m_strFromTime 
= null;
        m_strToTime 
= null;
    }


    
public void setHour(String strHour) {
        m_strHour 
= strHour;
    }


    
public void setMinute(String strMinute) {
        m_strMinute 
= strMinute;
    }


    
public void setSecond(String strSecond) {
        m_strSecond 
= strSecond;
    }


    
public void setTimeselector(String strTimeSelector) {
        m_strTimeSelector 
= strTimeSelector;
    }


    
public void setTimeformat(String strTimeFormat) {
        m_strTimeFormat 
= strTimeFormat;
    }


    
public void setTimestep(String strTimeStep) {
        m_strTimeStep 
= strTimeStep;
    }


    
public void setFromtime(String strFromTime) {
        m_strFromTime 
= strFromTime;
    }


    
public void setTotime(String strToTime) {
        m_strToTime 
= strToTime;
    }


    
protected Class getControlClass() {
        
return com.documentum.web.form.control.DateTime.class;
    }


    
protected boolean isDatafieldHandlerClass(Class cl) {
        
return cl.equals(com.documentum.web.form.control.DateTimeTag.class);
    }


    
protected void setControlProperties(Control control) {
        
super.setControlProperties(control);
        DateTime dateTime 
= (DateTime) control;
        
if (m_strTimeFormat != null)
            
if (m_strTimeFormat.equalsIgnoreCase("short"))
                dateTime.setTimeFormat(
3);
            
else
                
if (m_strTimeFormat.equalsIgnoreCase("medium"))
                    dateTime.setTimeFormat(
2);
                
else
                    
if (m_strTimeFormat.equalsIgnoreCase("long"))
                        dateTime.setTimeFormat(
1);
                    
else
                        
throw new WrapperRuntimeException("datetime tag 'timeformat' attribute value must be 'short', 'medium' or 'long'");
        
if (m_strTimeSelector != null)
            
if (m_strTimeSelector.equalsIgnoreCase("text"))
                dateTime.setTimeSelector(
2);
            
else
                
if (m_strTimeSelector.equalsIgnoreCase("list"))
                    dateTime.setTimeSelector(
0);
                
else
                    
if (m_strTimeSelector.equalsIgnoreCase("fields"))
                        dateTime.setTimeSelector(
1);
                    
else
                        
throw new WrapperRuntimeException("datetime tag 'timeselector' attribute value must be 'text', 'list' or 'field'");
        
if (m_strTimeStep != null)
            dateTime.setTimeStep(Integer.parseInt(m_strTimeStep));
        
if (m_strFromTime != null)
            dateTime.setFromTime(m_strFromTime);
        
if (m_strToTime != null)
            dateTime.setToTime(m_strToTime);
        
if (m_strHour != null && m_strHour.length() > 0 || m_strMinute != null && m_strMinute.length() > 0 || m_strSecond != null && m_strSecond.length() > 0{
            
int hour = 0;
            
int minute = 0;
            
int second = 0;
            
if (m_strHour != null)
                hour 
= Integer.parseInt(m_strHour);
            
if (m_strMinute != null)
                minute 
= Integer.parseInt(m_strMinute);
            
if (m_strSecond != null)
                second 
= Integer.parseInt(m_strSecond);
            dateTime.setHour(hour);
            dateTime.setMinute(minute);
            dateTime.setSecond(second);
        }

        
if (getDatafield() != null && isDatafieldHandlerClass(com.documentum.web.form.control.DateTimeTag.class)) {
            String strResult 
= resolveDatafield(getDatafield());
            
if (strResult != null{
                Date date 
= new Date((new Long(strResult)).longValue());
                DfTime dfTime 
= new DfTime(date);
                dateTime.setYear(dfTime.getYear());
                dateTime.setMonth(dfTime.getMonth());
                dateTime.setDay(dfTime.getDay());
                dateTime.setHour(dfTime.getHour());
                dateTime.setMinute(dfTime.getMinutes());
                dateTime.setSecond(dfTime.getSeconds());
            }

        }

        String strValue 
= dateTime.toDateTimeString(32);
        
if (strValue != null)
            dateTime.setValue(strValue);
    }


    
protected void renderEnd(JspWriter out) throws IOException {
        DateTime dateTime 
= (DateTime) getControl();
        
if (dateTime.isVisible()) {
            java.util.Locale locale 
= LocaleService.getLocale();
            Calendar calendar 
= Calendar.getInstance(locale);
            calendar.set(
101222);
            DateFormat df 
= DateFormat.getDateTimeInstance(32, locale);
            String strDate 
= df.format(calendar.getTime());
            out.print(
"<span class=\"dateTime\"");
            String title 
= dateTime.getToolTip();
            
if (title != null{
                out.print(
" title=\"");
                out.print(SafeHTMLString.escapeAttribute(title));
                out.print(
"\"");
            }

            out.print(
">");
            
int width = dateTime.getWidth();
            
if (strDate.indexOf("1"< strDate.indexOf("2")) {
                renderDate(out, dateTime, width 
/ 2);
                renderTime(out, dateTime, width 
/ 2);
            }
 else {
                renderTime(out, dateTime, width 
/ 2);
                renderDate(out, dateTime, width 
/ 2);
            }

            out.print(
"</span>");
        }

    }


    
protected void renderEventArg(StringBuffer buf, String strClientEvent, String strServerEvent) {
        
if (!strClientEvent.equals("onchange")) {
            
super.renderEventArg(buf, strClientEvent, strServerEvent);
        }
 else {
            DateTime control 
= (DateTime) getControl();
            
boolean hasEventHandler = control.getEventHandlerMethod(strServerEvent) != null;
            buf.append(
" ");
            buf.append(strClientEvent);
            buf.append(
"='");
            
if (hasEventHandler)
                buf.append(
"setKeys(event);");
            renderTimeUpdateCode(buf);
            
if (hasEventHandler)
                renderSubmitCode(buf, strServerEvent);
            buf.append(
"");
            
if (hasEventHandler && AccessibilityService.isAllAccessibilitiesEnabled()) {
                buf.append(
" onkeypress='");
                renderKeyPressSubmitCode(buf, strServerEvent);
                buf.append(
"");
            }

        }

    }


    
protected void renderDate(JspWriter out, DateInput dateInput, int width) throws IOException {
        StringBuffer scriptBuffer 
= new StringBuffer("<script type='text/javascript'>");
        scriptBuffer.append(
"function __onDateSet");
        scriptBuffer.append(dateInput.getElementName());
        scriptBuffer.append(
"() {");
        DateTime dateTime 
= (DateTime) getControl();
        
int timeSelector = dateTime.getTimeSelector();
        
if (timeSelector == 1{
            String dateId 
= dateTime.getElementName("date");
            String hourId 
= dateTime.getElementName("hour");
            String minuteId 
= dateTime.getElementName("minute");
            String secondId 
= dateTime.getElementName("second");
            scriptBuffer.append(
"var dateElements = document.getElementsByName('");
            scriptBuffer.append(dateId);
            scriptBuffer.append(
"');\n");
            scriptBuffer.append(
"var hourElements = document.getElementsByName('");
            scriptBuffer.append(hourId);
            scriptBuffer.append(
"');\n");
            scriptBuffer.append(
"var minuteElements = document.getElementsByName('");
            scriptBuffer.append(minuteId);
            scriptBuffer.append(
"');\n");
            scriptBuffer.append(
"var secondElements = document.getElementsByName('");
            scriptBuffer.append(secondId);
            scriptBuffer.append(
"');\n");
            scriptBuffer.append(
"if (dateElements != null && dateElements[0] != null && dateElements[0].value != null && dateElements[0].value.length == 0){ ");
            scriptBuffer.append(
"hourElements[0].selectedIndex = 0;");
            scriptBuffer.append(
"minuteElements[0].selectedIndex = 0;");
            scriptBuffer.append(
"secondElements[0].selectedIndex = 0;");
            scriptBuffer.append(
"return; }\n");
            scriptBuffer.append(
"if (hourElements != null && hourElements[0] != null && hourElements[0].selectedIndex == 0) {hourElements[0].selectedIndex = 1;}\n");
            scriptBuffer.append(
"if (minuteElements != null && minuteElements[0] != null && minuteElements[0].selectedIndex == 0) {minuteElements[0].selectedIndex = 1;}\n");
            scriptBuffer.append(
"if (secondElements != null && secondElements[0] != null && secondElements[0].selectedIndex == 0) {secondElements[0].selectedIndex = 1;}\n");
        }
 else
            
if (timeSelector == 0{
                String dateId 
= dateTime.getElementName("date");
                String timeId 
= dateTime.getElementName("time");
                scriptBuffer.append(
"var dateElements = document.getElementsByName('");
                scriptBuffer.append(dateId);
                scriptBuffer.append(
"');\n");
                scriptBuffer.append(
"var timeElements = document.getElementsByName('");
                scriptBuffer.append(timeId);
                scriptBuffer.append(
"');\n");
                scriptBuffer.append(
"if (dateElements != null && dateElements[0] != null && dateElements[0].value != null && dateElements[0].value.length == 0) { timeElements[0].selectedIndex = 0; return; }\n");
                scriptBuffer.append(
"if (timeElements[0].selectedIndex == 0) { timeElements[0].selectedIndex = 1;}\n");
            }
 else {
                String initialTimeValue 
= dateTime.toTimeString(dateTime.getTimeFormat());
                String timeId 
= dateTime.getElementName("time");
                scriptBuffer.append(
"var timeElements = document.getElementsByName('");
                scriptBuffer.append(timeId);
                scriptBuffer.append(
"');\n");
                scriptBuffer.append(
"if (timeElements != null && timeElements[0] != null && timeElements[0].value != null && timeElements[0].value.length == 0) { timeElements[0].value ='");
                scriptBuffer.append(initialTimeValue);
                scriptBuffer.append(
"'; }\n");
            }

        scriptBuffer.append(
"}\n");
        scriptBuffer.append(
"</script>");
        
if (dateInput.getDateSelectorType() == 0{
            scriptBuffer.append(
"<script type='text/javascript'>");
            String dayFieldId 
= dateInput.getElementName("day");
            String monthFieldId 
= dateInput.getElementName("month");
            String yearFieldId 
= dateInput.getElementName("year");
            scriptBuffer.append(
"function __updateTimeIfNeeded");
            scriptBuffer.append(dateInput.getElementName());
            scriptBuffer.append(
"(){ ");
            scriptBuffer.append(
"var dayElements = document.getElementsByName('");
            scriptBuffer.append(dayFieldId);
            scriptBuffer.append(
"');\n");
            scriptBuffer.append(
"var monthElements = document.getElementsByName('");
            scriptBuffer.append(monthFieldId);
            scriptBuffer.append(
"');\n");
            scriptBuffer.append(
"var yearElements = document.getElementsByName('");
            scriptBuffer.append(yearFieldId);
            scriptBuffer.append(
"');\n");
            scriptBuffer.append(
"if (dayElements != null && dayElements[0] != null && dayElements[0].selectedIndex != 0 && ");
            scriptBuffer.append(
"monthElements != null && monthElements[0] != null && monthElements[0].selectedIndex != 0 && ");
            scriptBuffer.append(
" yearElements != null && yearElements[0] != null && yearElements[0].selectedIndex != 0) {\n");
            scriptBuffer.append(
"__onDateSet");
            scriptBuffer.append(dateInput.getElementName());
            scriptBuffer.append(
"();}\n}\n");
            scriptBuffer.append(
"</script>");
        }

        String script 
= scriptBuffer.toString();
        out.write(script);
        
super.renderDate(out, dateInput, width);
    }


    
protected void renderTime(JspWriter out, DateTime dateTime, int width) throws IOException {
        
if (dateTime.getTimeSelector() == 2)
            renderTimeAsText(out, dateTime, width);
        
else
            
if (dateTime.getTimeSelector() == 0)
                renderTimeAsList(out, dateTime, width);
            
else
                
if (dateTime.getTimeSelector() == 1)
                    renderTimeAsFields(out, dateTime, width);
    }


    
protected void renderTimeUpdateCode(StringBuffer buf) {
        DateTime dateTime 
= (DateTime) getControl();
        
if (dateTime.getDateSelectorType() == 0)
            buf.append(
"__updateTimeIfNeeded");
        
else
            buf.append(
"__onDateSet");
        buf.append(dateTime.getElementName());
        buf.append(
"();");
    }


    
protected void renderTimeAsText(JspWriter out, DateTime dateTime, int width) throws IOException {
        StringBuffer buf 
= new StringBuffer(128);
        String strClass 
= dateTime.getCssClass();
        String strStyle 
= dateTime.getCssStyle();
        buf.append(
"<input type='text' ").append(renderNameAndId(getControl(), "time"));
        String title 
= dateTime.getToolTip();
        
if (title != null)
            buf.append(
" title=\"").append(SafeHTMLString.escapeAttribute(title)).append("\"");
        
if (strClass != null)
            buf.append(
" class='").append(strClass).append("'");
        
if (strStyle != null)
            buf.append(
" style='").append(strStyle).append("'");
        renderTabIndex(buf);
        String strTime 
= dateTime.toTimeString(dateTime.getTimeFormat());
        
if (strTime == null || strTime.length() == 0)
            strTime 
= getString("MSG_TIME");
        buf.append(
" value='").append(formatAttribute(strTime)).append("'");
        buf.append(
" style='width:").append(Math.max(width, 95)).append("px'");
        
if (!dateTime.isEnabled())
            buf.append(
" disabled='true'");
        buf.append(
"/>");
        out.print(buf.toString());
    }


    
protected void renderTimeAsList(JspWriter out, DateTime dateTime, int width) throws IOException {
        StringBuffer buf 
= new StringBuffer(128);
        String strClass 
= dateTime.getCssClass();
        String strStyle 
= dateTime.getCssStyle();
        buf.append(
"<select ").append(renderNameAndId(getControl(), "time"));
        String title 
= dateTime.getToolTip();
        
if (title != null)
            buf.append(
" title=\"").append(SafeHTMLString.escapeAttribute(title)).append("\"");
        
if (strClass != null{
            strClass 
= convertCssClass(strClass);
            buf.append(
" class='").append(strClass).append("'");
        }

        
if (strStyle != null)
            buf.append(
" style='").append(strStyle).append("'");
        renderTabIndex(buf);
        buf.append(
" size=0");
        
if (!dateTime.isEnabled())
            buf.append(
" disabled='true'");
        buf.append(
" style='width:").append(Math.max(width, 95)).append("px'");
        renderEventArg(buf, 
"onchange""onselect");
        buf.append(
">");
        java.util.Locale locale 
= LocaleService.getLocale();
        Calendar calendar 
= Calendar.getInstance(locale);
        calendar.setTime(
new Date());
        calendar.set(
11, Math.max(0, dateTime.getHour()));
        calendar.set(
12, Math.max(0, dateTime.getMinute()));
        calendar.set(
13, Math.max(0, dateTime.getSecond()));
        Date time 
= calendar.getTime();
        DateFormat df 
= DateFormat.getTimeInstance(3, locale);
        
long timeStep = dateTime.getTimeStep();
        
if (timeStep == 0L)
            timeStep 
= 1800L;
        Calendar from 
= parseTime(dateTime.getFromTime());
        Calendar to 
= parseTime(dateTime.getToTime());
        Date fromTime 
= from.getTime();
        Date toTime 
= to.getTime();
        Date item 
= fromTime;
        buf.append(
"<option value=''>").append(getString("MSG_TIME")).append("</option>");
        
do {
            String strTime 
= df.format(item);
            buf.append(
"<option value='").append(strTime).append("'");
            
if (item.getHours() == time.getHours() && item.getMinutes() == time.getMinutes() || item.getHours() == 12 && time.getHours() == 0 && item.getMinutes() == time.getMinutes())
                buf.append(
" SELECTED");
            buf.append(
">").append(strTime).append("</option>");
            item.setTime(item.getTime() 
+ timeStep * 1000L);
        }
 while (item.before(toTime) || item.equals(toTime));
        buf.append(
"</select>");
        out.print(buf.toString());
    }


    
protected void renderTimeAsFields(JspWriter out, DateTime dateTime, int width) throws IOException {
        StringBuffer buf 
= new StringBuffer(128);
        
boolean allowedToAddSeparator = false;
        width 
= Math.max(width / 365);
        
int timeStep = dateTime.getTimeStep();
        
if (timeStep == 0)
            timeStep 
= 1;
        String strQueuedFieldSeparator 
= "";
        DateInputTag.DateFormatTokenizer tokenizer 
= new DateInputTag.DateFormatTokenizer(getTimeFormat(1));
        
do {
            
if (!tokenizer.hasMoreTokens())
                
break;
            String strToken 
= tokenizer.nextToken();
            
if (strToken.equalsIgnoreCase("XX")) {
                buf.append(strQueuedFieldSeparator);
                strQueuedFieldSeparator 
= "";
                renderTimeField(buf, dateTime, 
"hour"0231"MSG_HOUR", width, dateTime.getHour());
                allowedToAddSeparator 
= true;
            }
 else
                
if (strToken.equalsIgnoreCase("YY")) {
                    
if (timeStep % 3600 != 0{
                        buf.append(strQueuedFieldSeparator);
                        strQueuedFieldSeparator 
= "";
                        renderTimeField(buf, dateTime, 
"minute"059, Math.max(1, timeStep / 60), "MSG_MINUTE", width, dateTime.getMinute());
                    }
 else {
                        dateTime.setMinute(
0);
                    }

                    allowedToAddSeparator 
= true;
                }
 else
                    
if (strToken.equalsIgnoreCase("ZZ")) {
                        
if (timeStep % 60 != 0{
                            buf.append(strQueuedFieldSeparator);
                            strQueuedFieldSeparator 
= "";
                            renderTimeField(buf, dateTime, 
"second"059, timeStep, "MSG_SECOND", width, dateTime.getSecond());
                        }
 else {
                            dateTime.setSecond(
0);
                        }

                        allowedToAddSeparator 
= true;
                    }
 else
                        
if (allowedToAddSeparator)
                            strQueuedFieldSeparator 
= (new StringBuilder()).append(strQueuedFieldSeparator).append(strToken).toString();
        }
 while (true);
        out.write(buf.toString());
    }


    
protected void renderTimeField(StringBuffer buf, DateTime dateTime, String strField, int from, int to, int step, String strDescId, int width, int value) {
        String strClass 
= dateTime.getCssClass();
        String strStyle 
= dateTime.getCssStyle();
        buf.append(
"<select ").append(renderNameAndId(getControl(), strField));
        String title 
= dateTime.getToolTip();
        
if (title != null)
            title 
= (new StringBuilder()).append(title).append(" ").append(getString(strDescId)).toString();
        
else
            title 
= getString(strDescId);
        buf.append(
" title=\"").append(SafeHTMLString.escapeAttribute(title)).append("\"");
        
if (strClass != null{
            strClass 
= convertCssClass(strClass);
            buf.append(
" class='").append(strClass).append("'");
        }

        
if (strStyle != null)
            buf.append(
" style='").append(strStyle).append("'");
        renderTabIndex(buf);
        buf.append(
" size=0");
        
if (!dateTime.isEnabled())
            buf.append(
" disabled='true'");
        buf.append(
" style='width:").append(width).append("px'");
        renderEventArg(buf, 
"onchange""onselect");
        buf.append(
">");
        buf.append(
"<option value=''>").append(getString(strDescId)).append("</option>");
        
for (int i = from; i <= to; i += step) {
            buf.append(
"<option value='").append(i).append("'");
            
if (value == i)
                buf.append(
" SELECTED");
            buf.append(
">");
            buf.append(i).append(
"</option>");
        }


        buf.append(
"</select>");
    }


    
protected static String getTimeFormat(int timeFormat) {
        java.util.Locale locale 
= LocaleService.getLocale();
        Calendar calendar 
= Calendar.getInstance(locale);
        calendar.setTime(
new Date());
        calendar.set(
1114);
        calendar.set(
1213);
        calendar.set(
1311);
        DateFormat df 
= DateFormat.getTimeInstance(timeFormat, locale);
        String strTimeFormat 
= df.format(calendar.getTime());
        strTimeFormat 
= StringUtil.replace(strTimeFormat, "02""XX");
        strTimeFormat 
= StringUtil.replace(strTimeFormat, "2""XX");
        strTimeFormat 
= StringUtil.replace(strTimeFormat, "14""XX");
        strTimeFormat 
= StringUtil.replace(strTimeFormat, "13""YY");
        strTimeFormat 
= StringUtil.replace(strTimeFormat, "11""ZZ");
        
return strTimeFormat;
    }


    
static Calendar parseTime(String strTime) {
        Calendar calendar 
= null;
        
int hour = -1;
        
int minute = 0;
        
int second = 0;
        
int index = 0;
        DateInputTag.DateFormatTokenizer tokenizer 
= new DateInputTag.DateFormatTokenizer(getTimeFormat(1));
        
do {
            
if (!tokenizer.hasMoreTokens())
                
break;
            String strToken 
= tokenizer.nextToken();
            
if (strToken.equalsIgnoreCase("XX")) {
                index 
= indexOfDigit(strTime, index);
                
if (index == -1)
                    
break;
                hour 
= parseInt(strTime, index);
                index 
+= String.valueOf(hour).length() + 1;
                
continue;
            }

            
if (strToken.equalsIgnoreCase("YY")) {
                index 
= indexOfDigit(strTime, index);
                
if (index == -1)
                    
break;
                minute 
= parseInt(strTime, index);
                index 
+= String.valueOf(minute).length() + 1;
                
continue;
            }

            
if (!strToken.equalsIgnoreCase("ZZ"))
                
continue;
            index 
= indexOfDigit(strTime, index);
            
if (index == -1)
                
break;
            second 
= parseInt(strTime, index);
            index 
+= String.valueOf(second).length() + 1;
        }
 while (true);
        
boolean bIsPm = strTime.toLowerCase().indexOf("pm"!= -1;
        
boolean bIsAm = strTime.toLowerCase().indexOf("am"!= -1;
        
if (bIsPm && hour < 12)
            hour 
+= 12;
        
if (bIsAm)
            
if (hour == 12)
                hour 
= 0;
            
else
                
if (hour > 12)
                    hour 
= -1;
        
if (hour == 24)
            hour 
= 0;
        
if (hour >= 0 && hour <= 23 && minute >= 0 && minute <= 59 && second >= 0 && second <= 59{
            calendar 
= Calendar.getInstance(LocaleService.getLocale());
            calendar.setTime(
new Date());
            calendar.set(
11, hour);
            calendar.set(
12, minute);
            calendar.set(
13, second);
        }

        
return calendar;
    }


    
protected void renderCalendar(JspWriter out, DateInput dateInput, int width) throws IOException {
        
if (dateInput.isVisible()) {
            StringBuffer buf 
= new StringBuffer(256);
            String title 
= dateInput.getToolTip();
            String strClass 
= dateInput.getCssClass();
            String strStyle 
= dateInput.getCssStyle();
            IThemeResolver themeResolver 
= BrandingService.getThemeResolver();
            String strDropDownImage 
= themeResolver.getResourcePath(dateInput.isEnabled() ? "images/date/dropdown.gif" : "images/date/dropdown_disabled.gif", getForm().getPageContext(), false);
            String strPrevMonthImage 
= themeResolver.getResourcePath("images/date/prevmonth.gif", getForm().getPageContext(), false);
            String strNextMonthImage 
= themeResolver.getResourcePath("images/date/nextmonth.gif", getForm().getPageContext(), false);
            Dimension imageExtents 
= ImageService.getDimensions(strDropDownImage, getForm().getPageContext());
            Calendar calendar 
= Calendar.getInstance(LocaleService.getLocale());
            
int firstDayOfWeek = calendar.getFirstDayOfWeek();
            StringBuffer dateFormatBuf 
= new StringBuffer();
            renderJavaScriptString(dateFormatBuf, getDateFormat(
3));
            String strShortDateFormat 
= dateFormatBuf.toString();
            dateFormatBuf.delete(
0, dateFormatBuf.length());
            renderJavaScriptString(dateFormatBuf, getDateFormat(
2));
            String strMediumDateFormat 
= dateFormatBuf.toString();
            dateFormatBuf.delete(
0, dateFormatBuf.length());
            renderJavaScriptString(dateFormatBuf, getDateFormat(
1));
            String strLongDateFormat 
= dateFormatBuf.toString();
            buf.append(
"<script src='").append(Form.makeUrl(getForm().getPageContext().getRequest(), "wdk/include/popupCalendar.js")).append("' type='text/javascript'></script>");
            buf.append(
"<input type='text' ").append(renderNameAndId(getControl(), "date"));
            
if (strClass != null)
                buf.append(
" class='").append(strClass).append("'");
            
if (strStyle != null)
                buf.append(
" style='").append(strStyle).append("'");
            renderTabIndex(buf);
            
if (title != null)
                buf.append(
" title=\"").append(SafeHTMLString.escapeAttribute(title)).append("\"");
            String strDate 
= dateInput.toDateString(dateInput.getDateFormat());
            
if (strDate == null || strDate.length() == 0{
                strDate 
= dateInput.getValue();
                
if (strDate == null || strDate.length() == 0{
                    strDate 
= getString("MSG_DATE");
                    setValue(strDate);
                    dateInput.setValue(strDate);
                    dateInput.updateOldValue();
                }

            }

            buf.append(
" value='").append(formatAttribute(strDate)).append("'");
            buf.append(
" style='width:").append(Math.max(95, width - (int) imageExtents.getWidth())).append("px'");
            
if (!dateInput.isEnabled())
                buf.append(
" disabled='true'");
            renderEventArg(buf, 
"onchange""onselect");
            buf.append(
"/>");
            buf.append(
"<img name='").append(dateInput.getElementName("date")).append("_anchor' src='").append(strDropDownImage).append("' width=").append((int) imageExtents.getWidth()).append(" height=").append((int) imageExtents.getHeight());
            
if (dateInput.isEnabled()) {
                buf.append(
" alt='").append(title == null ? "" : title).append(" ").append(getString("MSG_CALANDAR")).append("'");
                buf.append(
" onclick=\"popupCalendar('").append(getForm().getTopForm().getElementName()).append("','").append(dateInput.getElementName("date")).append("','").append(toStringFromStringArray(getShortWeekdays())).append("','").append(toStringFromStringArray(getShortMonths())).append("','").append(toStringFromStringArray(getMonths())).append("',").append(firstDayOfWeek - 1).append(",").append(dateInput.getDateFormat()).append(",'").append(strShortDateFormat).append("','").append(strMediumDateFormat).append("','").append(strLongDateFormat).append("','").append(getString("MSG_PREV_MONTH")).append("','").append(strPrevMonthImage).append("','").append(getString("MSG_NEXT_MONTH")).append("','").append(strNextMonthImage).append("');\"");
            }

            buf.append(
"/>");
            out.write(buf.toString());
        }

    }


    
static String[] getShortWeekdays() {
        java.util.Locale locale 
= LocaleService.createLocale("en_US");
        String days[] 
= DateUtil.getShortWeekdays(locale);
        
return days;
    }


    
protected static final int MIN_LIST_WIDTH = 95;
    
protected static final int MIN_TEXT_WIDTH = 95;
    
protected static final int MIN_FIELD_WIDTH = 65;
    
protected static final String HOUR_TOKEN = "XX";
    
protected static final String MINUTE_TOKEN = "YY";
    
protected static final String SECOND_TOKEN = "ZZ";
    
private String m_strHour;
    
private String m_strMinute;
    
private String m_strSecond;
    
private String m_strTimeSelector;
    
private String m_strTimeFormat;
    
private String m_strTimeStep;
    
private String m_strFromTime;
    
private String m_strToTime;
}

posted on 2009-08-02 16:30 liaojiyong 阅读(1464) 评论(2)  编辑  收藏 所属分类: Documentum

评论

# re: Webtop 6.5 DateTime控件选择日期时,星期几显示不全 2010-06-03 14:02

很厉害啊。  回复  更多评论   

# re: Webtop 6.5 DateTime控件选择日期时,星期几显示不全[未登录] 2014-09-04 10:03 test

能不能通过设置哪个属性来解决这个问题?
代码太多了  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航: