Hibernate Validator is useful for bean validations but it has nothing to do
with unique constraint for which you should consult database unless you
cache all the instances.

I would like to provide user with an early warning that the data it fills in
is not unique but I haven't found solution out of the box that uses entity
annotations, especially UniqueContraint.


Dorothée Giernoth wrote:
> 
> 
> 
> I would find this very useful! So a contribution to wicket-stuff would be
> awesome. Thnx.
> 
> - dg
>  
> -----Ursprüngliche Nachricht-----
> Von: Clint Popetz [mailto:cl...@42lines.net] 
> Gesendet: Dienstag, 19. Mai 2009 13:49
> An: users@wicket.apache.org
> Betreff: Re: How to validate unique constraint?
> 
> 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
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-validate-unique-constraint--tp23610946p23629304.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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

Reply via email to