0

I'm implementing a multilanguage page which allow use to select their desire language. I have implemented something like this and everything work perfectly. JSF 2.0 set locale throughout session from browser and programmatically

However, when I click to change my language, the whole page is refreshed and the locale for all the text is changed, but the text i input in the form also gone. Example: 1. I have locale in English and got a form with input Username 2. I enter "ABC" in username 3. I click on the change language link to Chinese language 4. Username become Chinese word 5. "ABC" I entered previously is gone.

Is it possible to change the language and in the same time preserving my input? I tried use ajax but similar issue happen. I need to use @all as I got menu, footer and other text which is not in the form to be translated.

Sample of my code:

<h:commandLink immediate="true" value="#{msg[localeType.resourceKey]}" 
    rendered="#{languageBean.isCurrentLocale(localeType.value) == false}">
    <f:ajax render="label" execute="@all" 
          listener="#{customerDetailBean.preserveFormData(localeType.value)}"/>
</h:commandLink>

Thanks in advance for the great help.

Community
  • 1
  • 1
Alex
  • 541
  • 4
  • 3
  • 1
    You're rendering all your content again, but you still don't have the current input in your managed bean. There are three options: 1. [Use keyup event](http://mkblog.exadel.com/2010/04/learning-jsf-2-ajax-in-jsf-using-fajax-tag/) to invoke an ajax call when user enters something into any input. Personally I don't like that because it performs a request per key hit, resulting not friendly for the user. 2. Make your language change `commandLink` update the form at server side before rendering the whole page. 3. Don't render the inputs, just the content you want to translate (the most proper). – Aritz Nov 29 '13 at 09:41
  • Thanks a lot Xtreme Biker for your suggestions. Seems like I need to use option number 2 as I need to translate every single label which I was unable to do so using option 3. – Alex Dec 02 '13 at 02:37

0 Answers0