Bug 45620 - formatDate fails when locale is missing
Summary: formatDate fails when locale is missing
Status: RESOLVED WONTFIX
Alias: None
Product: Taglibs
Classification: Unclassified
Component: I18N Taglib (show other bugs)
Version: unspecified
Hardware: All Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords: NeedsReleaseNote
Depends on:
Blocks:
 
Reported: 2008-08-12 06:34 UTC by Phil Dicke
Modified: 2009-07-10 00:37 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.