Yes, I've been reading a bit about the Seam framework, it looks
extremely promising. However, I need a solution that I can plug in to
our existing Hibernate-Spring-JSF framework, and I don't think
introducing Seam is an option right now. But I'll definitely keep my eye
on it, it has some very nice features...
Jurgen
Jacob Hookom schreef:
There might be some overlap here with Seam-- we've already implemented
some of this.
Sylvain Vieujot wrote:
I agree, it would be very nice and avoid double validation code for
the hibernate users.
It would also prevent meaning less errors for the users and show the
exact problem.
Great idea !
Sylvain.
On Sat, 2006-03-11 at 17:45 +0100, Jurgen Lust wrote:
How about this approach?
1. You annotate your model classes with Hibernate Validator
annotations, for example @Range(min=10, max=20)
2. You don't put any validators in the JSPs
3. You implement a custom PropertyResolverImpl that does the
following:
1. set the property
2. perform the validation with HibernateValidator on the
property
3. if the value is invalid, set the property to its original
value and throw an EvaluationException
4. The JSP is rendered with a FacesMessage next to the
input, containing the Hibernate Validator error message.
Advantages:
* All validation is in 1 place, the model class, where it belongs
* Much cleaner JSP
Disadvantages:
* You completely bypass the JSF process validations phase,
however, since the custom PropertyResolver would reset the
property to its old value when a validation error occurs, this
would not really be a problem.
This approach would not work at the moment, or at least until
MYFACES-1157 is fixed.
Any ideas?
Jurgen
Jurgen Lust schreef:
Hi,
I've been playing around with Hibernate Annotations a bit, and
noticed that there is also something like the Hibernate Validator:
http://www.hibernate.org/hib_docs/annotations/reference/en/html/validator.html
This allows you to specify constraints on your model classes, using
jdk 5.0 annotations. Hibernate then automatically enforces these
contraints in the persistence tier of your application.
Now I was thinking that this could also be used with JSF. Instead
of putting all the JSF validation stuff in the JSPs, you should be
able to use those annotations in the validate phase.
Has anyone tried this yet? Would it be possible, and are there any
pitfalls?
regards,
Jurgen
- Re: hibernate validator Jurgen Lust
-