[ http://issues.apache.org/struts/browse/STR-1892?page=comments#action_37383 ]
Ralf Hauser commented on STR-1892: ---------------------------------- see also STR-2435 and SB-20 > timezone support for bean:write tag > ----------------------------------- > > Key: STR-1892 > URL: http://issues.apache.org/struts/browse/STR-1892 > Project: Struts Action 1 > Type: Improvement > Components: Taglibs > Versions: 1.1 Final > Environment: Operating System: other > Platform: All > Reporter: Dam Cho > Assignee: Struts Developer Mailing List > Priority: Minor > > currently as of version 1.2 of Struts custom tag library, timezone is not > configurable for using bean:write tag with Date object. Both JSTL and apache > date custom tags support converting date value to that of different timezone. > below is a subclass I created to accomodate timezone configuration. Something > like this would do.. > public class WriteDateTag extends WriteTag { > private String timeZoneString; > > public void setTimezone(String timeZoneString) { > this.timeZoneString = timeZoneString; > } > > public String getTimezoneString() { > return timeZoneString; > } > > /** > * Format value according to specified format string (as tag attribute > or > * as string from message resources) or to current user locale. > * > * @param valueToFormat value to process and convert to String > * @exception JspException if a JSP exception has occurred > */ > protected String formatValue(Object valueToFormat) throws JspException { > Format format = null; > Object value = valueToFormat; > Locale locale = > RequestUtils.retrieveUserLocale(pageContext, > this.localeKey); > boolean formatStrFromResources = false; > String formatString = formatStr; > // Try to retrieve format string from resources by the key from > formatKey. > if( ( formatString==null ) && ( formatKey!=null ) ) { > formatString = retrieveFormatString( this.formatKey ); > if( formatString!=null ) > formatStrFromResources = true; > } > if (formatString == null) { > if (value instanceof java.sql.Timestamp) { > formatString = > retrieveFormatString(SQL_TIMESTAMP_FORMAT_KEY); > } else if (value instanceof java.sql.Date) { > formatString = > retrieveFormatString(SQL_DATE_FORMAT_KEY); > } else if (value instanceof java.sql.Time) { > formatString = > retrieveFormatString(SQL_TIME_FORMAT_KEY); > } else if (value instanceof java.util.Date) { > formatString = > retrieveFormatString(DATE_FORMAT_KEY); > } > if (formatString != null) > formatStrFromResources = true; > } > > TimeZone tz = null; > if (timeZoneString != null) { > tz = TimeZone.getTimeZone(timeZoneString); > } else { > tz = TimeZone.getDefault(); > } > if (formatString != null) { > if (formatStrFromResources) { > format = new SimpleDateFormat(formatString, > locale); > } else { > format = new SimpleDateFormat(formatString); > } > } > > > if (format != null) { > ((SimpleDateFormat) format).setTimeZone(tz); > return format.format(value); > } else { > return value.toString(); > } > } > } -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/struts/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira
