Important update (2015-11-12)
A more recent implementation is available in all projets generated by Celerio.
Follow our doc to ** generate in a few minutes ** your first project with Celerio
How to skip JSF BeanValidation conditionally
Here is a trick that allows you to perform JSF-based BeanValidation depending on the action.
The challenge when developing JSF applications involving multi-page form is to provide a usable navigation between the pages.
By usable navigation we mean:
a user should be able to navigate freely from one page to another without loosing the data entered in the input fields, even if the entered data is invalid, so that the user can come back to it later.
for certain actions, for example a ‘save’ action, the validation should be enforced.
The solution should be easy to develop and maintain. For example, we have tried to implement the a trick that Mr Ed Burns suggests, without any success.
JSF 2.0 supports BeanValidation, which is extremely convenient. We should leverage it.
We leverage the
binding attribute of the JSF
As the documentation says, this attribute value is a ValueExpression that evaluates to an object that implements javax.faces.validate.BeanValidator
Unsurprisingly BeanValidator implements the
validate method below from the
We just have to extend
BeanValidator and override the
validate method, here is the code:
Of course the code above may be improved to fit your need and your security requirements.
How to use it
Then, to use it from your view, you simply do as follow:
If you have any remark on this solution, please share :)
The SpringFuse/Jaxio team.
comments powered by