Class FacesLocal


  • public final class FacesLocal
    extends Object

    Collection of utility methods for the Faces API that are mainly shortcuts for obtaining stuff from the provided FacesContext argument. In effect, it 'flattens' the hierarchy of nested objects.

    The difference with Faces is that no one method of FacesLocal obtains the FacesContext from the current thread by FacesContext.getCurrentInstance(). This job is up to the caller. This is more efficient in situations where multiple utility methods needs to be called at the same time. Invoking FacesContext.getCurrentInstance() is at its own an extremely cheap operation, however as it's to be obtained as a ThreadLocal variable, it's during the call still blocking all other running threads for some nanoseconds or so.

    Note that methods which are directly available on FacesContext instance itself, such as FacesContext.getExternalContext(), FacesContext.getViewRoot(), FacesContext.isValidationFailed(), etc are not delegated by the this utility class, because it would design technically not make any sense to delegate a single-depth method call like follows:

     ExternalContext externalContext = FacesLocal.getExternalContext(facesContext);
     

    instead of just calling it directly like follows:

     ExternalContext externalContext = facesContext.getExternalContext();
     

    Usage

    Some examples (for the full list, check the API documentation):

     FacesContext context = Faces.getContext();
     User user = FacesLocal.getSessionAttribute(context, "user");
     Item item = FacesLocal.evaluateExpressionGet(context, "#{item}");
     String cookieValue = FacesLocal.getRequestCookie(context, "cookieName");
     List<Locale> supportedLocales = FacesLocal.getSupportedLocales(context);
     FacesLocal.invalidateSession(context);
     FacesLocal.redirect(context, "login.xhtml");
     
    Since:
    1.6
    Author:
    Arjan Tijms, Bauke Scholtz
    See Also:
    Servlets