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:
@Override
public void
processValidators(FacesContext context) {
// I told you it's simple
}
Update model
should be suppressed ? Than do the same for processUpdates():
@Override
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:
@Override
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