My JSF Books/Videos My JSF Tutorials OmniFaces/JSF PPTs
JSF 2.3 Tutorial
JSF Caching Tutorial
JSF Navigation Tutorial
JSF Scopes Tutorial
JSF Page Author Beginner's Guide
OmniFaces 2.3 Tutorial Examples
OmniFaces 2.2 Tutorial Examples
JSF Events Tutorial
OmniFaces Callbacks Usages
JSF State Tutorial
JSF and Design Patterns
JSF 2.3 New Features (2.3-m04)
Introduction to OmniFaces
25+ Reasons to use OmniFaces in JSF
OmniFaces Validators
OmniFaces Converters
JSF Design Patterns
Mastering OmniFaces
Reusable and less-verbose JSF code

My JSF Resources ...

Java EE Guardian
Member of JCG Program
Member MVB DZone
Blog curated on ZEEF
OmniFaces is an utility library for JSF, including PrimeFaces, RichFaces, ICEfaces ...

.

.

.

.

.

.

.

.


[OmniFaces Utilities] - Find the right JSF OmniFaces 2 utilities methods/functions

Search on blog

Petition by Java EE Guardians

Twitter

joi, 12 martie 2015

[OmniFaces utilities (2.0)] Get/set the Faces context attribute value associated with the given name


[OmniFaces utilities] The getContextAttribute() method returns the Faces context attribute value associated with the given name.
[OmniFaces utilities] The setContextAttribute() method sets the Faces context attribute value associated with the given name.

Methods:


Practically, these two methods allows an easy access to the FacesContext.getAttributes() map. These map is used by JSF to store specific information, but it can be used by the JSF programmers also. You can put here any information that should be available during current context.

Usage:

import org.omnifaces.util.Faces;
...
// add the attribute named, request.date
Faces.setContextAttribute("request.date", new java.util.Date());

Now, the attributes map may look like this:

The key is: com.sun.faces.RESOURCE_REQUEST                    value is :false
The key is: facelets.Encoding                                 value is :UTF-8
The key is: javax.faces.FACELET_CONTEXT                       value is :com.sun.faces.facelets.impl.DefaultFaceletContext@4f17a4cb
The key is: com.sun.faces.renderKitImplForRequest             value is :com.sun.faces.renderkit.RenderKitFactoryImpl@5528c72b
The key is: org.primefaces.context.RequestContext             value is :org.primefaces.context.DefaultRequestContext@1a7e2967
The key is: org.omnifaces.context.OmniPartialViewContext      value is :org.omnifaces.context.OmniPartialViewContext@2fdfa57
The key is: com.sun.faces.INVOCATION_PATH                     value is :.xhtml
The key is: SavedResponseCompleteFlagValue                    value is :false
The key is: request.date                                      value is :Fri Mar 13 08:13:40 EET 2015
The key is: com.sun.faces.logicalViewMap                      value is :-3131292308220084045
The key is: com.sun.faces.actualViewMap                       value is :5309957350313295661
The key is: javax.faces.component.UIViewRoot@5d014bb6         value is :true
...

The OmniFaces, getContextAttribute() can be used to access by name any of these attributes - the above highlighted was extracted below:

import org.omnifaces.util.Faces;
...
// returns false
boolean stage = Faces.getContextAttribute("com.sun.faces.RESOURCE_REQUEST");
// returns Fri Mar 13 08:13:40 EET 2015
Date date = Faces.getContextAttribute("request.date");
// instance of OmniPartialViewContext
OmniPartialViewContext omniPartialViewContext = Faces.getContextAttribute("org.omnifaces.context.OmniPartialViewContext");

Niciun comentariu :

Trimiteți un comentariu

JSF BOOKS COLLECTION

Postări populare

OmniFaces/JSF Fans

Visitors Starting 4 September 2015

Locations of Site Visitors