Hi,
I have this <h:selectOneMenu> tag where the user can change the language.
<h:selectOneMenu value="#{loginBean.langue}" valueChangeListener="#{loginBean.changerLangueComboBox}" onchange="submit()" >
<f:selectItem itemLabel="Langue" itemValue="langue"/>
<f:selectItem itemLabel="Français" itemValue="fr"/>
<f:selectItem itemLabel="Anglais" itemValue="en"/>
</h:selectOneMenu>
Here is the method of the managed bean :
public void changerLangueComboBox(ValueChangeEvent event) {
FacesContext context = FacesContext.getCurrentInstance();
if ("en".equals((String) event.getNewValue())){
context.getViewRoot().setLocale(Locale.UK);
this.locale = Locale.UK;
} else if ("fr".equals((String) event.getNewValue())) {
context.getViewRoot().setLocale(Locale.FRENCH);
this.locale = Locale.FRENCH;
}
log.info("context.getViewRoot().getLocale() is : " + context.getViewRoot().getLocale());
}
The method is called but the values of the current view are not updated. They are updated if i refresh the page.
Here are the sequence of phases calls :
1) User changes the language :
20:11:18,127 INFO [STDOUT] Processing new Request!
20:11:18,128 INFO [STDOUT] before - RESTORE_VIEW 1
20:11:18,141 INFO [STDOUT] after - RESTORE_VIEW 1
20:11:18,141 INFO [STDOUT] before - APPLY_REQUEST_VALUES 2
20:11:18,141 INFO [STDOUT] after - APPLY_REQUEST_VALUES 2
20:11:18,141 INFO [STDOUT] before - PROCESS_VALIDATIONS 3
20:11:18,142 INFO [LoginBean] context.getViewRoot().getLocale() is : fr
20:11:18,142 INFO [STDOUT] after - PROCESS_VALIDATIONS 3
20:11:18,143 INFO [STDOUT] before - RENDER_RESPONSE 6
20:11:18,150 INFO [STDOUT] after - RENDER_RESPONSE 6
20:11:18,150 INFO [STDOUT] Done with Request!
2) User refreshes the page :
20:11:37,402 INFO [STDOUT] Processing new Request!
20:11:37,402 INFO [STDOUT] before - RESTORE_VIEW 1
20:11:37,417 INFO [STDOUT] after - RESTORE_VIEW 1
20:11:37,417 INFO [STDOUT] before - APPLY_REQUEST_VALUES 2
20:11:37,418 INFO [STDOUT] after - APPLY_REQUEST_VALUES 2
20:11:37,418 INFO [STDOUT] before - PROCESS_VALIDATIONS 3
20:11:37,419 INFO [STDOUT] after - PROCESS_VALIDATIONS 3
20:11:37,419 INFO [STDOUT] before - UPDATE_MODEL_VALUES 4
20:11:37,419 INFO [STDOUT] after - UPDATE_MODEL_VALUES 4
20:11:37,419 INFO [STDOUT] before - INVOKE_APPLICATION 5
20:11:37,420 INFO [STDOUT] after - INVOKE_APPLICATION 5
20:11:37,420 INFO [STDOUT] before - RENDER_RESPONSE 6
20:11:37,428 INFO [STDOUT] after - RENDER_RESPONSE 6
20:11:37,428 INFO [STDOUT] Done with Request!
Obviously, the UPDATE_MODEL_VALUES et INVOKE_APPLICATION phases are skipped the first time.
Question : why are they skipped and how can i call them ?
Well I did manage to call these 2 phases the first time with these 2 lines :
event.setPhaseId(PhaseId.UPDATE_MODEL_VALUES);
event.queue();
In that case all phases are called. Still, I need to refresh the page to get the chosen language.
Thanks in advance for helping.