Bug 32904

Summary: <i18n:formatDate /> does not handle locale changes properly - fix included here
Product: Taglibs Reporter: John DeNeut <jack>
Component: I18N TaglibAssignee: Tomcat Developers Mailing List <dev>
Severity: major    
Priority: P2    
Version: nightly   
Target Milestone: ---   
Hardware: All   
OS: Mac OS X 10.3   

Description John DeNeut 2004-12-31 16:03:36 UTC
<i18n:formatDate /> does not handle Locale changes properly in Tomcat/5.0.16 on
Mac OS X 10.3.6 because the Locale is cached (actually, the DateFormat is
cached, but it ends up causing the same problem). 

The problem is in i18n.FormatDateTag, right here: 

/** If no {@link java.text.DateFormat} is configured then use a 
      * {@link SimpleDateFormat} instance if a pattern is configured else
      * use the default DateFormat for the {@link java.util.Locale}
    public Format getFormat() {
        /* if ( format == null ) { */
            String pattern = getPattern();
            if ( pattern != null ) {
                format = getPatternFormat( pattern );
            if ( pattern == null ) {
                format = getDateFormat();
       /* } */
        return format;

When tags are pooled(?) the variable 'format' gets set the first time the tag is
used in the container, and can then not be changed. The fix is to do what I did
above - that is, take out the check for 'format' being null and simply redo the
formatting every time. 

Note that <i18n:formatDateTime /> works fine.  I used both tags on the same page
and switched my locale back and forth.  <i18n:formatDateTime /> responds to the
change in Locale, but <i18n:formatDate /> does not.  My fix (above) solves this
Comment 1 Henri Yandell 2009-07-10 00:36:36 UTC
JSTL replaced the i18n taglib, so this won't be worked on.