Questions about Bean Validation vs JSF validation?
I have some questions about Bean Validatio开发者_开发技巧n and JSF validation, currently I am using Bean validation:
- With the JSF validation, the validation works client side only, no request sent to server, and Bean validation works on server?
- If javascript is disabled are both will work JSF & Bean Validation, or only bean validation?
- What are the disadvantages of Bean validation if there are any?
That is not true. The validations are applied during the jsf life cycle by
Process Validations
."Conversion and validation occurs when the JSF runtime calls the processValidators() method on each component in the view hierarchy. The processValidators() method will first initiate any data conversion that is required before validating the components value against the application’s validation rules. If there are any errors during the conversion or validation process the component is marked invalid and an error message is generated and queued in the FacesContext object. If a component is marked invalid, JSF advances directly to the render response phase, which will display the current view with the queued validation error messages. If there are no validation errors, JSF advances to the update model values phase." - johnderinger.wordpress.com
You can also find this information in the specification.
Both work without
javascript
.This is more a question of programming style. I think validation is better made in the model than in the view, because it removes logic from the view and it is more DRY (don't repeat yourself). If you use a bean multiple time, you will have to write the validation only once with bean validation. You should also know that bean validation overwrite constraints in JSF.
More information how to use bean validation, you can find here and the specification here. For more information about the integrated JSF validation, you should visit this site.
精彩评论