-
Available since OmniFaces 1.6
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
Here are some examples:
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");
For a full list, check the method summary.
Feature request
If you know more useful methods/functions which you think should be added to this OmniFaces utility class so that everyone can benefit from a "standard" Faces utility library, feel free to post a feature request.