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

sâmbătă, 14 martie 2015

[OmniFaces utilities (2.0/2.2)] Get the view parameters of the current view


[OmniFaces utilities] The getViewParameters() method returns the view parameters of the current view, or an empty collection if there is no view.
[OmniFaces utilities] The getViewParameterMap() method returns the view parameters of the current view as a parameter map, or an empty map if there is no view. This is ready for usage in among others ViewHandler#getBookmarkableURL(FacesContext, String, Map, boolean).

Method Faces#getViewParameters() - return view parameters as a Collection:

Method Faces#getViewParametersMap() - return view parameters as a Map (starting with OmniFaces 2.2, this method become mutable):
Usage:

Let's suppose that we have three view parameters, defined as:
...
<f:metadata>
 <f:viewParam name="email" value="#{loginBean.email}"/>
 <f:viewParam name="info" value="#{loginBean.info}"/>
 <f:viewParam name="type" value="guest"/>
</f:metadata>
...

Now, in a managed bean (or in other JSF artifact) you can "capture" the list of view parameters as below:

·         as a Collection:
import org.omnifaces.util.Faces;
...
Collection<UIViewParameter> vpsColl = Faces.getViewParameters();

·         as a Map:
import org.omnifaces.util.Faces;
...
Map<String, List<String>> vpsMap = Faces.getViewParameterMap();   

Note The <f:viewParam> doesn't support multiple values anyway, so having multiple <f:viewParam> on the same request parameter shouldn't end up in repeated parameters in action URL:

parameterMap.put(viewParameter.getName(), Collections.singletonList(value)); // OmniFaces 2.0
parameterMap.put(viewParameter.getName(), asList(value)); // OmniFaces 2.2

So, if you have a request to populate the view parameters, like:

http://host:port/app_name/?email=rafa@rg.com&info=Rafa%20wins%20RG%20again!

Then, Faces#getViewParameters() and Faces.getViewParameterMap() will reveal something like this (suppose that you have print to console the name and value of each view parameter):

Name: email Value: rafa@rg.com
Name: info  Value: Rafa wins RG again!
Name: type  Value: guest

Niciun comentariu :

Trimiteți un comentariu

JSF BOOKS COLLECTION

Postări populare

OmniFaces/JSF Fans

Visitors Starting 4 September 2015

Locations of Site Visitors