I have the following JSF code to display a date using a certain pattern.
<f:convertDateTime pattern="E, d MMM, yyyy" timeZone="#{localeBean.timeZone}" />
I would like to pass the pattern to this via the localeBean also. Is there any way to determine the specific pattern based on the locale?
public LocaleBean() {
this.defaultTimeZone = TimeZone.getDefault();
this.strLocale = Locale.getDefault().toString();
this.timeZone = defaultTimeZone.getDisplayName();
}
The f:convertDateTime
provides the type
, dateStyle
and timeStyle
attributes for this which is dependent on the viewroot's locale.
Assuming Facelets:
<!DOCTYPE html>
<html lang="#{localeBean.language}"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<f:view locale="#{localeBean.locale}">
<h:head>
<title>SO question 4792373</title>
</h:head>
<h:body>
<h:outputText value="#{bean.date}">
<f:convertDateTime type="date" dateStyle="short" />
</h:outputText>
<br />
<h:outputText value="#{bean.date}">
<f:convertDateTime type="date" dateStyle="medium" />
</h:outputText>
<br />
<h:outputText value="#{bean.date}">
<f:convertDateTime type="date" dateStyle="long" />
</h:outputText>
<br />
<h:outputText value="#{bean.date}">
<f:convertDateTime type="date" dateStyle="full" />
</h:outputText>
</h:body>
</f:view>
</html>
Here's how it renders like with English locale:
1/25/11 Jan 25, 2011 January 25, 2011 Tuesday, January 25, 2011
German:
25.01.11 25.01.2011 25. Januar 2011 Dienstag, 25. Januar 2011
Dutch:
25-1-11 25-jan-2011 25 januari 2011 dinsdag 25 januari 2011
French:
25/01/11 25 janv. 2011 25 janvier 2011 mardi 25 janvier 2011
Etc..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With