0

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Jakeway
  • 241
  • 1
  • 2
  • 10
  • `FacesContext.getCurrentInstance()` will be `null` if the request is not attended by `FacesServlet`, which seems to be your case. I would recommend not refreshing the page through ajax. – Luiggi Mendoza Feb 06 '15 at 17:13
  • @LuiggiMendoza, yes I know why it is null, but is there another way to refresh page without reloading? – Jakeway Feb 06 '15 at 17:20

0 Answers0