Issue Details (XML | Word | Printable)

Key: STR-1892
Type: Improvement Improvement
Status: Closed Closed
Resolution: Won't Fix
Priority: Minor Minor
Assignee: Struts Developers
Reporter: Dam Cho
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Struts 1

timezone support for bean:write tag

Created: 23/Dec/03 04:01 PM   Updated: 04/Jul/07 05:29 AM
Component/s: Tag Libraries
Affects Version/s: 1.1.0
Fix Version/s: None

Environment:
Operating System: other
Platform: All

Bugzilla Id: 25719


 Description  « Hide
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();
}
}
}

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
David Graham added a comment - 26/Dec/03 10:55 PM
Struts tags that duplicate functionality of the standard taglib are in
maintenance mode and are not actively enhanced. The best solution is to use the
JSTL.

Ralf Hauser added a comment - 22/May/06 12:47 PM
see also STR-2435 and SB-20