internationaling: changing locale from the header

Hello all, happy new year!

I am facing this problem: I have a page fragment with italiano/english links to switch betweeen it_IT and en_Us locales, using

public String italianoHyperlink_action(){

Locale locale =new Locale("it","IT");

FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);

returnnull;

}

The issue is: how can I set up a dropdown list with string in the correct language? If I do this in the code adding the proper options to the list with something like

Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();

ResourceBundle bundle = ResourceBundle.getBundle("mypackage/Bundle", locale);

myMenu.add(new Option(bundle.getString(key), value))

I have to refresh the page after clicking on the header links, because the page fragment code is executedafter the rest of the code and the locale is switchedafter the dropdown list is rendered.

Do you see any workaround for this?

thanks in advance

Mauro

[1347 byte] By [maurozooma] at [2007-11-26 13:51:51]
# 1

I am assuming that there is an action component on the page with the drop-down list, that is used to submit the page, and it is bound to the action method that you list above.

If so, the problem is probably that the drop-down list is not being updated after the action is handled and the application locale has been changed.

The easiest way to guarantee that things happen in the write order is to bind the drop-down component to a property of type array of Option, and update the options dynamicaly in the property getter, e.g.

public Option[] getMyOptions() {

Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();

ResourceBundle bundle = ResourceBundle.getBundle("mypackage/Bundle", locale);

return new Option[] {new Option(bundle.getString(key), value))};

}

// Gregory

Message was edited by:

gjmurphy

Message was edited by:

gjmurphy

gjmurphya at 2007-7-8 1:29:19 > top of Java-index,Development Tools,Java Tools...