Bug 45620

Summary: formatDate fails when locale is missing
Product: Taglibs Reporter: Phil Dicke <philci52>
Component: I18N TaglibAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED WONTFIX    
Severity: normal Keywords: NeedsReleaseNote
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: Windows XP   

Description Phil Dicke 2008-08-12 06:34:17 UTC
Some browsers (IE from GoogleEarth) do not pass local information in the HTTP header for the request, therefore request.getLocale() returns null.  When this happens the following tag fails even though a pattern and timezone are specified:

<fmt:formatDate value="${d}" pattern="yyyy-MM-dd HH:mm z" timeZone="GMT"/>
The above just prints out d.toString()

SimpleDateFormat has all the elements it needs for a successful format, it should format the date as expected instead of using d.toString()


Workaround:
You can add the following to your JSP and it will work.
<c:choose>
    <c:when test="${request.locale == null}">
        <fmt:setLocale value="en_US" />
    </c:when>
</c:choose>
Comment 1 Nicky Sandhu 2009-02-09 16:53:37 UTC
Another easy workaround without touching jsp pages is to set either the default fallback locale or the default locale via web.xml configuration
<context-param>
<param-name>
  javax.servlet.jsp.jstl.fmt.locale
</param-name>
<param-value>
  en
</param-value>
</context-param>
<context-param>
<param-name>
  javax.servlet.jsp.jstl.fmt.fallbackLocale
</param-name>
<param-value>
  en
</param-value>
</context-param>
Comment 2 Henri Yandell 2009-07-10 00:37:45 UTC
JSTL replaced the i18n taglib, so this won't be worked on.