I am trying to internationalize my web application, so I am using a ResourceBundle and dynamically changing the locale using:
FacesContext.getCurrentInstance()
.getViewRoot().setLocale(locale);
Which worked fine at first. But I am trying to use an AJAX call to update the page, and the program uses a third party servlet to handle the AJAX calls. So now when my bean gets called, it keeps getting a null exception (since I am not in the FacesServlet, I'm in some other servlet).
The code to call the ajax looks like
<revit:button id="ajaxMe" type="button"
onClick="primeAjaxCall();localeCodeChanged();">Select Language</revit:button>
<revit:ajax method="#{stringbean.localeCodeChanged}"
call="localeCodeChanged" callback="ajaxCallback" postData="parameter" />
The managed bean code:
public AJAXResponse localeCodeChanged(Map<String, String[]> parameterMap, Map<String, String> headers)
{
// read in the parameters to get the locale
// how can I effectively call this without null pointer?
FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
}
Any ideas?