开发者

JSF Validation Best Practices

开发者 https://www.devze.com 2023-01-26 11:31 出处:网络
I\'m currently learning about JSF 2.0 and i would like to ask about how to do UI validations in a good way.

I'm currently learning about JSF 2.0 and i would like to ask about how to do UI validations in a good way. I notice that in JSF 2, validation has predefined tags so that it could be used across manya JSF pages, and we can even build our own validators.

But one thing that concerns me is that when i develop around hundreds of JSF pages, and many of the validations are the same, and it开发者_如何学编程 is hard to manage this centrally.

For example, for my currency input which has id of "PaymentAmount", is heavily used in many JSF pages. It has it's own unique validation rules, which define the fraction digits, min and max, etc. If im to use the validator tags in the JSF pages, there will be many copy paste involved. And if im to change the rules of this "PaymentAmount", i'll have to change in many JSF pages.

I would like to have the validations offered by the JSF like the date validation, required, range, etc, but without all the duplicates across JSF pages.

Is there any ideas to cope with this problem ?


Use the Bean Validation API introduced w/ Java EE 6:

http://download.oracle.com/javaee/6/tutorial/doc/gircz.html

Define all you validation centrally in your POJOs, and re-use throughout your application.

0

精彩评论

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