Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had a related problem recently. In my case, the JSF implementation forgot the view locale set by <code>UIViewRoot.setLocale()</code> after navigating to a different view. I rather consider this a bug in the JSF impl, but I didn't have time to make sure.</p> <p>I didn't particularly like the <code>&lt;f:view&gt;</code> approach, as that tag has been obsoleted by facelets - except for keeping the locale, it seems. This made my leary of including it in a Facelets template. I therefore wrote the following PhaseListener:</p> <pre><code>/** * PhaseListener that keeps the current view locale in the session while no request is being processed, to work around * bugs where JSF forgets the changed locale. */ public class SaveViewLocaleToSessionPhaseListener implements PhaseListener { private static final String key = "locale"; @Override public PhaseId getPhaseId() { return PhaseId.ANY_PHASE; } @Override public void beforePhase(PhaseEvent event) { // do nothing } @Override public void afterPhase(PhaseEvent event) { PhaseId currentPhase = event.getPhaseId(); if (currentPhase == PhaseId.RESTORE_VIEW) { viewRoot().setLocale((Locale) sessionMap().get(key)); } else if (currentPhase == PhaseId.RENDER_RESPONSE) { sessionMap().put(key, viewRoot().getLocale()); } } private Map&lt;String, Object&gt; sessionMap() { return FacesContext.getCurrentInstance().getExternalContext().getSessionMap(); } private UIViewRoot viewRoot() { return FacesContext.getCurrentInstance().getViewRoot(); } } </code></pre> <p>However, I can not offer any solid evidence that this is really better than simply using <code>&lt;f:view&gt;</code>.</p> <blockquote> <p>But, I haven't changed the locale of JSF itself in any way. </p> </blockquote> <p>Sure you did: The <code>&lt;f:view&gt;</code> tag reads the locale from the value expression, and passes it to <code>UIViewRoot.setLocale()</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload