开发者

Questions about Bean Validation vs JSF validation?

开发者 https://www.devze.com 2023-04-07 02:17 出处:网络
I have some questions about Bean Validatio开发者_开发技巧n and JSF validation, currently I am using Bean validation:

I have some questions about Bean Validatio开发者_开发技巧n and JSF validation, currently I am using Bean validation:

  1. With the JSF validation, the validation works client side only, no request sent to server, and Bean validation works on server?
  2. If javascript is disabled are both will work JSF & Bean Validation, or only bean validation?
  3. What are the disadvantages of Bean validation if there are any?


  1. 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.

  2. Both work without javascript.

  3. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消