• cdi
  • components
  • contexts
  • converters
  • eventlisteners
  • exceptionhandlers
  • facesviews
  • filters
  • functions
  • managedbeans
  • push
  • resourcehandlers
  • scripts
  • servlets
  • taghandlers
  • utils
  • validators
  • viewhandlers
-
  • Ajax
  • Beans
  • BeansLocal
  • Components
  • Events
  • Exceptions
  • Faces
  • FacesConfigXml
  • FacesLocal
  • JNDI
  • Messages
  • Servlets
  • WebXml

Collection of utility methods for the JSF 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");

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" JSF utility library, feel free to post a feature request.

Documentation & Sources