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


marți, 10 februarie 2015

OmniFaces technique for suppressing JSF default tasks in custom components

Sometimes, you need to suppress specific JSF tasks in your custom components. Per example, if you have a custom component which doesn't have a model value (like, OmniFaces ComponentIdParam component), then you may need to totally suppress validation and/or model update. Well, the solution is provided by OmniFaces and it is very simple - it consist in overriding the proper UIComponent.processXxx() method(s) and leave the method body empty. You can easily suppress validation by overriding the processValidators() method, as below:

public void processValidators(FacesContext context) {
 // I told you it's simple

Update model should be suppressed ? Than do the same for processUpdates():

public void processUpdates(FacesContext context) {
 // I told you it's simple

The same technique can be applied to processDecodes(), processRestoreState(), processSaveState(). Generally speaking, you can apply this simple technique to suppress other JSF default tasks also. Per example, if you want to suppress the "cascade" call of encodeBegin(), encodeChildren(), encodeEnd(), then you can simply override the encodeAll() method:

 public void encodeAll(FacesContext context) throws IOException {
 // no rendering now

Note Obviously, the idea is simple and we can find a lot of examples for it. But, the important things are: to totally understand the side effects of it, to know what method(s) should be overriden, and to know when to use it. Novices may not anticipate the need of suppressing JSF default tasks, simply because they don't have the "big picture" of what is happening when their custom component is integrated in page, and implicitly in JSF lifecycle.

Niciun comentariu :

Trimiteți un comentariu


Postări populare

OmniFaces/JSF Fans

Follow by Email

Visitors Starting 4 September 2015

Locations of Site Visitors