• Post Reply Bookmark Topic Watch Topic
  • New Topic

rich:calendar and locale

 
Michael Maurer
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using rich:calendar in my multi-lingual JSF app. Users can switch between English, French, German, Italian, and Dutch as the display language. The rich:calendar component is supposed to be locale aware, and I have the locale attribute set on it. When the locale changes in the current FacesContext, everything on the page changes to the new language and locale, including the popup calendar. But the display field portion of the rich:calendar (the text area that displays the selected date) does not. The date remains in the previous locale and then fails validation when the form is submitted. I have to manually pop up the calendar again and re-select the date in order to get it to validate. This is unacceptable because some of the date fields contain default values, and they need to change to the new locale/language along with the rest of the page.

Can anyone help with a workaround for this? How can I get the selected date to automatically change to the new selected locale without having to re-select it?

I am using RichFaces 3.3.1

JSF snippet:


Java bean snippet:
 
Tim Holloway
Bartender
Posts: 18413
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The FacesContext is destroyed and re-created for each JSF request. You are not "storing the locale in the FacesContext".

What you need is a backing bean (e.g., localeBean) with session scope to hold that locale info. Don't use request scope because request scope beans are likewise destroyed and re-created, so the locale information will repeatedly reset. View Scope is probably not a safe option either. Plus, it's unlikely that only one View is going to be locale-sensitive.

The locale information MUST be set BEFORE the View is initially displayed. This is one reason why I like my webapps to have a public landing page. That page can gather up user information such as browser type, locale, current window size and so forth and transmit it to the server so that the actual working pages will have what they need.
 
Michael Maurer
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am already storing the locale in a session scoped backing bean.
When a different language is selected, all text on all pages in the entire app changes to the selected language. The rich:calendar component (the popup calendar) changes to the selected language. Everything appears to work as it should, except for the selected date being displayed in the text area of the rich:calendar component. It remains in the original language and fails validation when the page is submitted.
 
Tim Holloway
Bartender
Posts: 18413
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I'm getting misdirected by the use of "changes to", since it implies changes AFTER the page was displayed when you PROBABLY mean that NEW pages display with the locale set properly.

Regardless, you have a date pattern in your tag. It's almost certainly overriding the locale.
 
Michael Maurer
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I am using a date pattern. Today's date displays as "09-May-2014" in english, and "09-Mai-2014" in french.

See attached screenshots for an example.

cal1.jpg = In French language, select dates from rich:calendar component.
cal2.jpg = Switch to English language. Page displays in English, but dates are still in French and fail validation.
cal1.jpg
[Thumbnail for cal1.jpg]
French
cal2.jpg
[Thumbnail for cal2.jpg]
Switch to English, but French dates still displayed and won't validate
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!