Localization in JSF, how to remember selected locale per session instead of per request/view

后端 未结 5 1142
夕颜
夕颜 2020-11-22 04:36

faces-config.xml:


    
        ru
        

        
5条回答
  •  无人及你
    2020-11-22 05:09

    If you can use CDI and deltaspike (JSF module) in your environment, you could add the following to your LocaleBean to automatically reset the locale on the current view:

    @javax.enterprise.context.SessionScoped
    public class LocaleBean implements Serializable {
    
        ...
    
        public void resetLocale(@Observes @BeforePhase(JsfPhaseId.RENDER_RESPONSE) PhaseEvent event) {
            event.getFacesContext().getViewRoot().setLocale(this.locale);
        }
    }
    

提交回复
热议问题