Question

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 ?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top