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

marți, 27 octombrie 2015

OmniFaces 2.2 ViewParam with default value

View parameters have been introduced starting with JSF 2.0. They appear nested in the metadata section and their main goal is to sustain the developer to provide bookmarkable URLs.

View parameters are stateful and they need to be initialized only once. This is great because they are available in the current view over postbacks, even if they no longer appear in the URL (they may appear only at initial request). But, there are a few drawbacks of this behavior ‐ they are not bugs, but as you will see, they can lead to performance problems:

·         Invoke the setter method at each postback
·         Break stateful character leads to problems with the required built‐in validator
·         Invoke the converter regardless the null values

OmniFaces fix these issues via ViewParam component (<o:viewParam>) which is stateless. How this component works and it is implemented is presented in Mastering OmniFaces book.

Starting with OmniFaces 2.2, this component support a new attribute named, default. Via this attribute we can initialize (set a default value)  a view parameter. Per example, let's check the below example:

<f:metadata>            
 <f:viewParam name="phone" value="#{phoneBean.phone}"/>
 <o:viewParam name="prefix" default="001" value="#{phoneBean.prefix}"/>
</f:metadata>
<h:body>              
 #{phoneBean.prefix}-#{phoneBean.phone}
</h:body>

@Named
@RequestScoped
public class PhoneBean {
   
 private String prefix;
 private String phone;
  
 // getters and setters
}

We can see the effect of the default attribute by "juggling" with the initial request query string:

- both view parameters are initialized via query string (default attribute is ignored)

http://localhost:8080/ViewParamWithDefaultValue/?phone=825890&prefix=0721
Output: 0721-825890

- only phone view parameter is initialized via query string (default value is used since prefix doesn't have a value):

http://localhost:8080/ViewParamWithDefaultValue/?phone=825890
Output: 001-825890

The complete application is available here.

Niciun comentariu :

Trimiteți un comentariu

JSF BOOKS COLLECTION

Postări populare

OmniFaces/JSF Fans

Visitors Starting 4 September 2015

Locations of Site Visitors