Excellent. Thanks for the additional feedback Ture.
One other option would be to put another getter method,
getDatePattern(), on the page flow that would return a localized
pattern (could also be looked up from a properties file). Then the
formatDate tag could be written as
<netui:formatDate pattern="${pageFlow.datePattern}"
language="${pageFlow.language}"/>
Carlin
On 9/20/06, Ture Hoefner <[EMAIL PROTECTED]> wrote:
Hello Mika,
In an application that I have worked on we get the date pattern from a
PropertyResourceBundle by looking it up from a .properties file. We are then
careful to keep track of the Locale that matches the PropertyResourceBundle for
the date pattern so that we can use the same Locale wherever we do any date
formatting.
When we look up a PropertyResourceBundle in a POJO we use an algorithm that matches the
one that JSTL uses in the <fmt> tags, as described in the JSTL spec, section 8.3,
8.3.1, 8.3.2,etc. In a JSP we use the JSTL <fmt> tags to lookup the date pattern.
Because we are not necessarily using the primary Locale from the HttpServletRequest
(request.getLocale()), but could be using any of the Locales from request.getLocales(), we keep
track of which Locale we are using. In a POJO we just use ResourceBundle.getLocale() to figure
out which Locale matches our .properties file. In a JSP, where we used <fmt:bundle> and
<fmt:message> to get the date pattern, we use <fmt:setBundle> and
javax.servlet.jsp.jstl.fmt.LocalizationContext.getLocale() to figure out which Locale we are
using, like this:
<fmt:bundle basename="com.whatever.DateFormats">
<fmt:message var="datePattern" key="date.pattern" />
</fmt:bundle>
<fmt:setBundle basename="com.whatever.DateFormats"
var="dateFormatLocalizationContext" />
<%
...
...
...
// The date pattern was looked up from a ResourceBundle. We are
careful to use the
// same Locale as the ResourceBundle when we do date formatting.
// That is why we use the LocalizationContext to find the Locale
// instead of getting it from request.getLocale()...they could be
different locales because
// of the JSTL algorithm used for getting the locale for L10N.
LocalizationContext dateFormatLocalizationContext = (LocalizationContext)
pageContext.findAttribute( "dateFormatLocalizationContext" );
Locale dateLocale = dateFormatLocalizationContext.getLocale();
...
...
...
%>
-------------------
Ture Hoefner
WebLogic Portal Engineering
BEA Systems, Inc.
> -----Original Message-----
> From: Mika Rinne
> Sent: Wednesday, September 20, 2006 9:39 AM
> To: Beehive Users
> Subject: VS: dateFormat localization question
>
> Thanks a lot Carlin!
>
> Not sure what kind of results this would produce without trying out myself
> but assuming it will translate the month based on visitors locals (stored
> in the session).
>
> What if one wants to localize the date pattern itself as well? Like we
> know in many occasions date format varies between countries. How could
> that be resolved using the dateFormat tag ?
>
> For example:
> 31.12.2006 or 31. Tammikuuta 2006 (Finland)
> 12/31/2006 or January 31st 2006 (U.S)
>
> Thanks again
> Mika
>
> -----Alkuperäinen viesti-----
> Lähettäjä: Carlin Rogers [mailto:[EMAIL PROTECTED]
> Lähetetty: ke 20.9.2006 16:05
> Vastaanottaja: Beehive Users
> Kopio:
> Aihe: Re: dateFormat localization question
>
>
>
> Hi Mika,
>
> One possible solution would be to create a getter method,
> getLanguage(), on the page flow that returns the language value from
> the user's locale in the session. The PageFlowController class that
> a
> user extends has a protected method, getLocale(), that returns the
> "currently selected Locale, stored in the session." Then the
> language
> value of the Locale object could be returned from the page flow
> method, getLocale().
>
> In the JSP, the expression ${pageFlow.language} would get the
> language value at runtime from the page flow. From the example you
> provided, the formatDate tag might look like this...
>
> <netui:formatDate pattern="MMMM dd, yyyy"
> language="${pageFlow.language}"/>
>
> Others on the list might have some additional thoughts as well. Hope
> that helps.
>
> Kind regards,
> Carlin
>
> On 9/20/06, Mika Rinne <[EMAIL PROTECTED]> wrote:
> > Hi everyone,
> >
> > I recently came accross this question but couldn't find an answer.
> Maybe someone of you are able to help:
> >
> > "I am using the netui:formatDate tag as follows:
> >
> > <netui:label value="{container.item.publishedDate}"
> defaultValue=" ">"><netui:formatDate pattern="MMMM dd, yyyy"
> language="en"/></netui:label>
>
> >
> > I would like to have language attribute set at runtime via
> session/request/pageflow. It doesn't seem to allow.
> >
> > I would like to localize the date at runtime, and cannot fix it by
> using a specific language."
> >
> > Thanks & regards
> >
> > Mika Rinne
> >
> > BEA Systems, Inc
> >
> > >>Register now for BEA World 2006 --- See
> http://www.bea.com/beaworld<<
> >
> _______________________________________________________________________
> > Notice: This email message, together with any attachments, may
> contain
> > information of BEA Systems, Inc., its subsidiaries and
> affiliated
> > entities, that may be confidential, proprietary, copyrighted
> and/or
> > legally privileged, and is intended solely for the use of the
> individual
> > or entity named in this message. If you are not the intended
> recipient,
> > and have received this message in error, please immediately return
> this
> > by email and then delete it.
> >
>
> >>Register now for BEA World 2006 --- See http://www.bea.com/beaworld<<
> _______________________________________________________________________
> Notice: This email message, together with any attachments, may contain
> information of BEA Systems, Inc., its subsidiaries and affiliated
> entities, that may be confidential, proprietary, copyrighted and/or
> legally privileged, and is intended solely for the use of the individual
> or entity named in this message. If you are not the intended recipient,
> and have received this message in error, please immediately return this
> by email and then delete it.
>>Register now for BEA World 2006 --- See http://www.bea.com/beaworld<<
_______________________________________________________________________
Notice: This email message, together with any attachments, may contain
information of BEA Systems, Inc., its subsidiaries and affiliated
entities, that may be confidential, proprietary, copyrighted and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.