It's relatively straightforward to use the hibernate validator api to
apply JPA constraints:

import org.hibernate.validator.*;
InvalidValue[] invalidValues = new
ClassValidator(MyModel.class).getInvalidValues(instanceOfMyModel);

This can also be done per-property; see the javadocs.

I've done this locally; if folks would find it useful I'll contribute
it to wicketstuff.

-Clint

On Tue, May 19, 2009 at 2:15 AM, Christian Helmbold
<christian.helmb...@yahoo.de> wrote:
>
> How can I validate a unique constraint with Wicket? Because only the value of 
> an input field is passed to onValidate(IValidatable validatable), there is no 
> chance to check if this value belongs to a specific object to update or if it 
> would violate a unique constraint when creating a new object. onValidate 
> would need another paremeter for the related object.
>
> I see two possibilities:
>
> a) Use a form validator and get the related model object from the form.
>
> b) Pass the related object to the constructor of the Validator. I'm not sure, 
> if the validator would be recreated any time the model object changes.
>
> I would prefer a validator tied to the field and not to the form, because 
> that would be more intuitive.
>
> Another idea is to use existing JPA annotations. @Column(unique=true) is 
> already there but not used for validation (outside the database). Perhaps 
> there is a way to use this annotation. I really like the domain level 
> validation of Grails: http://grails.org/doc/1.1/guide/7.%20Validation.html
>
> How would you validate a unique constraint with wicket?
>
> Thanks in advance
> Christian
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>



-- 
Clint Popetz
http://42lines.net
Scalable Web Application Development

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to