Re: Trying Hibernate Validator Integration

2009-03-14 Thread taha siddiqi
in your Application::init();

addComponentOnBeforeRenderListener( new HIbernateValidator() );

This will add validators to every @Entity | @Embeddable properties
using Hibernate validators
which are acting as CompoundModel()'s Objects in a Form

taha

On Sun, Mar 15, 2009 at 11:03 AM, Will Jaynes  wrote:
> I guess I'm not sure what you mean. Can you please show a code snippet?
>
> On Sun, Mar 15, 2009 at 1:04 AM, taha siddiqi  wrote:
>
>> I actually used it as a listener and at component level in my project.
>>
>> I will try to add this feature to it..
>>
>> Thanks
>> taha
>>
>> On Sun, Mar 15, 2009 at 10:17 AM, Will Jaynes  wrote:
>> > Taha, I've tried playing with  your HibernateValidator. It seems
>> necessary
>> > to add it to each form field. If I add it simply to the form, the
>> validation
>> > behavior doesn't happen. Am I missing something?
>> > Will
>> >
>> > On Sat, Mar 14, 2009 at 9:06 AM, taha siddiqi 
>> wrote:
>> >
>> >> I was myself very much interested and finally I found
>> >>
>> >> wicket-hibernate at
>> >>
>> >>
>> http://www.jroller.com/wireframe/entry/hibernateannotationcomponentconfigurator
>> >>
>> >> and wicket-jpa at
>> >> http://perfbench.googlecode.com/svn/trunk/perfbench/wicket-jpa/
>> >>
>> >> Then I came up which something that works for me ( already in the post )
>> >>
>> >> taha
>> >>
>> >>
>> >> On Sat, Mar 14, 2009 at 6:16 PM, Will Jaynes  wrote:
>> >> > In the archives, back in 2007, I see a lot of discussion about
>> >> Hibernate/JPA
>> >> > validator and Wicket, but I can't find if there was any result from
>> those
>> >> > discussions. Did anything come of it?
>> >> >
>> >> > Will
>> >> >
>> >> > On Tue, Mar 10, 2009 at 11:29 AM, taha siddiqi > >> >wrote:
>> >> >
>> >> >> but then how to get a ResourceBundle from wicket resource ??
>> >> >>
>> >> >>
>> >> >> On Tue, Mar 10, 2009 at 8:43 PM, Peter Thomas 
>> >> wrote:
>> >> >> > On Tue, Mar 10, 2009 at 9:04 AM, taha siddiqi <
>> tawushaf...@gmail.com>
>> >> >> wrote:
>> >> >> >
>> >> >> >> But the problem is when you begin to use the wicket resource
>> files,
>> >> >> >> hibernate-validator comes with its own messages and need to be
>> >> >> >> integrated with wicket ( which i was not able to )
>> >> >> >
>> >> >> >
>> >> >> > There is some info here on how to pass a resource-bundle to the
>> >> >> > ClassValidator constructor, I haven't tried it though:
>> >> >> >
>> >> >> >
>> >>
>> http://www.jboss.org/index.html?module=bb&op=viewtopic&t=69783&view=next
>> >> >> >
>> >> >> >
>> >> >> >>
>> >> >> >>
>> >> >> >> taha
>> >> >> >>
>> >> >> >> On Tue, Mar 10, 2009 at 8:11 PM, Peter Thomas <
>> ptrtho...@gmail.com>
>> >> >> wrote:
>> >> >> >> > On Tue, Mar 10, 2009 at 7:35 AM, taha siddiqi <
>> >> tawushaf...@gmail.com>
>> >> >> >> wrote:
>> >> >> >> >
>> >> >> >> >> Hi,
>> >> >> >> >>
>> >> >> >> >> I was working with Hibernate-validator and thought of sharing
>> the
>> >> >> code.
>> >> >> >> >>
>> >> >> >> >
>> >> >> >> > Taha: I thought the ClassValidator will handle all the different
>> >> cases
>> >> >> >> and
>> >> >> >> > annotations for you, see line #89
>> >> >> >> >
>> >> >> >> >
>> >> >> >>
>> >> >>
>> >>
>> http://code.google.com/p/perfbench/source/browse/trunk/perfbench/wicket-jpa/src/main/java/wicketjpa/wicket/EditBorder.java#89
>> >> >> >> >
>> >> >> >> > Is there any advantage of mapping each type (e.g. Min, Max,
>> >> >> >> > CreditCardNumber) to Wicket built-in validators ?
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >>
>> >> >> >> >> It is a listener as well as a behavior which can be used at
>> >> >> >> >> application level as well as with individual
>> >> >> >> >> components.
>> >> >> >> >>
>> >> >> >> >> It is heavily inspired from wicket-jpa and wicket-hibernate
>> >> >> >> >> projects... I just tried some changes...
>> >> >> >> >>
>> >> >> >> >> import java.util.Map;
>> >> >> >> >> import java.util.Arrays;
>> >> >> >> >> import java.util.List;
>> >> >> >> >> import java.util.Date;
>> >> >> >> >> import java.util.concurrent.ConcurrentHashMap;
>> >> >> >> >> import javax.persistence.Entity;
>> >> >> >> >> import javax.persistence.Embeddable;
>> >> >> >> >> import java.lang.reflect.Field;
>> >> >> >> >> import java.lang.reflect.Method;
>> >> >> >> >> import java.lang.annotation.Annotation;
>> >> >> >> >> import java.lang.reflect.AnnotatedElement;
>> >> >> >> >>
>> >> >> >> >> import org.hibernate.validator.NotNull;
>> >> >> >> >> import org.hibernate.validator.Length;
>> >> >> >> >> import org.hibernate.validator.NotEmpty;
>> >> >> >> >> import org.hibernate.validator.Min;
>> >> >> >> >> import org.hibernate.validator.Pattern;
>> >> >> >> >> import org.hibernate.validator.Max;
>> >> >> >> >> import org.hibernate.validator.Range;
>> >> >> >> >> import org.hibernate.validator.Past;
>> >> >> >> >> import org.hibernate.validator.Future;
>> >> >> >> >> import org.hibernate.validator.Email;
>> >> >> >> >> import org.hibernate.validator.CreditCardNumber;
>> >> >> >> >>
>> >> >> >> >> import org.apache.wicket.va

Re: Trying Hibernate Validator Integration

2009-03-14 Thread Will Jaynes
I guess I'm not sure what you mean. Can you please show a code snippet?

On Sun, Mar 15, 2009 at 1:04 AM, taha siddiqi  wrote:

> I actually used it as a listener and at component level in my project.
>
> I will try to add this feature to it..
>
> Thanks
> taha
>
> On Sun, Mar 15, 2009 at 10:17 AM, Will Jaynes  wrote:
> > Taha, I've tried playing with  your HibernateValidator. It seems
> necessary
> > to add it to each form field. If I add it simply to the form, the
> validation
> > behavior doesn't happen. Am I missing something?
> > Will
> >
> > On Sat, Mar 14, 2009 at 9:06 AM, taha siddiqi 
> wrote:
> >
> >> I was myself very much interested and finally I found
> >>
> >> wicket-hibernate at
> >>
> >>
> http://www.jroller.com/wireframe/entry/hibernateannotationcomponentconfigurator
> >>
> >> and wicket-jpa at
> >> http://perfbench.googlecode.com/svn/trunk/perfbench/wicket-jpa/
> >>
> >> Then I came up which something that works for me ( already in the post )
> >>
> >> taha
> >>
> >>
> >> On Sat, Mar 14, 2009 at 6:16 PM, Will Jaynes  wrote:
> >> > In the archives, back in 2007, I see a lot of discussion about
> >> Hibernate/JPA
> >> > validator and Wicket, but I can't find if there was any result from
> those
> >> > discussions. Did anything come of it?
> >> >
> >> > Will
> >> >
> >> > On Tue, Mar 10, 2009 at 11:29 AM, taha siddiqi  >> >wrote:
> >> >
> >> >> but then how to get a ResourceBundle from wicket resource ??
> >> >>
> >> >>
> >> >> On Tue, Mar 10, 2009 at 8:43 PM, Peter Thomas 
> >> wrote:
> >> >> > On Tue, Mar 10, 2009 at 9:04 AM, taha siddiqi <
> tawushaf...@gmail.com>
> >> >> wrote:
> >> >> >
> >> >> >> But the problem is when you begin to use the wicket resource
> files,
> >> >> >> hibernate-validator comes with its own messages and need to be
> >> >> >> integrated with wicket ( which i was not able to )
> >> >> >
> >> >> >
> >> >> > There is some info here on how to pass a resource-bundle to the
> >> >> > ClassValidator constructor, I haven't tried it though:
> >> >> >
> >> >> >
> >>
> http://www.jboss.org/index.html?module=bb&op=viewtopic&t=69783&view=next
> >> >> >
> >> >> >
> >> >> >>
> >> >> >>
> >> >> >> taha
> >> >> >>
> >> >> >> On Tue, Mar 10, 2009 at 8:11 PM, Peter Thomas <
> ptrtho...@gmail.com>
> >> >> wrote:
> >> >> >> > On Tue, Mar 10, 2009 at 7:35 AM, taha siddiqi <
> >> tawushaf...@gmail.com>
> >> >> >> wrote:
> >> >> >> >
> >> >> >> >> Hi,
> >> >> >> >>
> >> >> >> >> I was working with Hibernate-validator and thought of sharing
> the
> >> >> code.
> >> >> >> >>
> >> >> >> >
> >> >> >> > Taha: I thought the ClassValidator will handle all the different
> >> cases
> >> >> >> and
> >> >> >> > annotations for you, see line #89
> >> >> >> >
> >> >> >> >
> >> >> >>
> >> >>
> >>
> http://code.google.com/p/perfbench/source/browse/trunk/perfbench/wicket-jpa/src/main/java/wicketjpa/wicket/EditBorder.java#89
> >> >> >> >
> >> >> >> > Is there any advantage of mapping each type (e.g. Min, Max,
> >> >> >> > CreditCardNumber) to Wicket built-in validators ?
> >> >> >> >
> >> >> >> >
> >> >> >> >>
> >> >> >> >> It is a listener as well as a behavior which can be used at
> >> >> >> >> application level as well as with individual
> >> >> >> >> components.
> >> >> >> >>
> >> >> >> >> It is heavily inspired from wicket-jpa and wicket-hibernate
> >> >> >> >> projects... I just tried some changes...
> >> >> >> >>
> >> >> >> >> import java.util.Map;
> >> >> >> >> import java.util.Arrays;
> >> >> >> >> import java.util.List;
> >> >> >> >> import java.util.Date;
> >> >> >> >> import java.util.concurrent.ConcurrentHashMap;
> >> >> >> >> import javax.persistence.Entity;
> >> >> >> >> import javax.persistence.Embeddable;
> >> >> >> >> import java.lang.reflect.Field;
> >> >> >> >> import java.lang.reflect.Method;
> >> >> >> >> import java.lang.annotation.Annotation;
> >> >> >> >> import java.lang.reflect.AnnotatedElement;
> >> >> >> >>
> >> >> >> >> import org.hibernate.validator.NotNull;
> >> >> >> >> import org.hibernate.validator.Length;
> >> >> >> >> import org.hibernate.validator.NotEmpty;
> >> >> >> >> import org.hibernate.validator.Min;
> >> >> >> >> import org.hibernate.validator.Pattern;
> >> >> >> >> import org.hibernate.validator.Max;
> >> >> >> >> import org.hibernate.validator.Range;
> >> >> >> >> import org.hibernate.validator.Past;
> >> >> >> >> import org.hibernate.validator.Future;
> >> >> >> >> import org.hibernate.validator.Email;
> >> >> >> >> import org.hibernate.validator.CreditCardNumber;
> >> >> >> >>
> >> >> >> >> import org.apache.wicket.validation.validator.StringValidator;
> >> >> >> >> import org.apache.wicket.validation.validator.PatternValidator;
> >> >> >> >> import org.apache.wicket.validation.validator.NumberValidator;
> >> >> >> >> import
> >> org.apache.wicket.validation.validator.EmailAddressValidator;
> >> >> >> >> import
> org.apache.wicket.validation.validator.CreditCardValidator;
> >> >> >> >> import org.apache.wicket.validation.validator.DateValidator;
> >> >> >

Re: Trying Hibernate Validator Integration

2009-03-14 Thread taha siddiqi
I actually used it as a listener and at component level in my project.

I will try to add this feature to it..

Thanks
taha

On Sun, Mar 15, 2009 at 10:17 AM, Will Jaynes  wrote:
> Taha, I've tried playing with  your HibernateValidator. It seems necessary
> to add it to each form field. If I add it simply to the form, the validation
> behavior doesn't happen. Am I missing something?
> Will
>
> On Sat, Mar 14, 2009 at 9:06 AM, taha siddiqi  wrote:
>
>> I was myself very much interested and finally I found
>>
>> wicket-hibernate at
>>
>> http://www.jroller.com/wireframe/entry/hibernateannotationcomponentconfigurator
>>
>> and wicket-jpa at
>> http://perfbench.googlecode.com/svn/trunk/perfbench/wicket-jpa/
>>
>> Then I came up which something that works for me ( already in the post )
>>
>> taha
>>
>>
>> On Sat, Mar 14, 2009 at 6:16 PM, Will Jaynes  wrote:
>> > In the archives, back in 2007, I see a lot of discussion about
>> Hibernate/JPA
>> > validator and Wicket, but I can't find if there was any result from those
>> > discussions. Did anything come of it?
>> >
>> > Will
>> >
>> > On Tue, Mar 10, 2009 at 11:29 AM, taha siddiqi > >wrote:
>> >
>> >> but then how to get a ResourceBundle from wicket resource ??
>> >>
>> >>
>> >> On Tue, Mar 10, 2009 at 8:43 PM, Peter Thomas 
>> wrote:
>> >> > On Tue, Mar 10, 2009 at 9:04 AM, taha siddiqi 
>> >> wrote:
>> >> >
>> >> >> But the problem is when you begin to use the wicket resource files,
>> >> >> hibernate-validator comes with its own messages and need to be
>> >> >> integrated with wicket ( which i was not able to )
>> >> >
>> >> >
>> >> > There is some info here on how to pass a resource-bundle to the
>> >> > ClassValidator constructor, I haven't tried it though:
>> >> >
>> >> >
>> http://www.jboss.org/index.html?module=bb&op=viewtopic&t=69783&view=next
>> >> >
>> >> >
>> >> >>
>> >> >>
>> >> >> taha
>> >> >>
>> >> >> On Tue, Mar 10, 2009 at 8:11 PM, Peter Thomas 
>> >> wrote:
>> >> >> > On Tue, Mar 10, 2009 at 7:35 AM, taha siddiqi <
>> tawushaf...@gmail.com>
>> >> >> wrote:
>> >> >> >
>> >> >> >> Hi,
>> >> >> >>
>> >> >> >> I was working with Hibernate-validator and thought of sharing the
>> >> code.
>> >> >> >>
>> >> >> >
>> >> >> > Taha: I thought the ClassValidator will handle all the different
>> cases
>> >> >> and
>> >> >> > annotations for you, see line #89
>> >> >> >
>> >> >> >
>> >> >>
>> >>
>> http://code.google.com/p/perfbench/source/browse/trunk/perfbench/wicket-jpa/src/main/java/wicketjpa/wicket/EditBorder.java#89
>> >> >> >
>> >> >> > Is there any advantage of mapping each type (e.g. Min, Max,
>> >> >> > CreditCardNumber) to Wicket built-in validators ?
>> >> >> >
>> >> >> >
>> >> >> >>
>> >> >> >> It is a listener as well as a behavior which can be used at
>> >> >> >> application level as well as with individual
>> >> >> >> components.
>> >> >> >>
>> >> >> >> It is heavily inspired from wicket-jpa and wicket-hibernate
>> >> >> >> projects... I just tried some changes...
>> >> >> >>
>> >> >> >> import java.util.Map;
>> >> >> >> import java.util.Arrays;
>> >> >> >> import java.util.List;
>> >> >> >> import java.util.Date;
>> >> >> >> import java.util.concurrent.ConcurrentHashMap;
>> >> >> >> import javax.persistence.Entity;
>> >> >> >> import javax.persistence.Embeddable;
>> >> >> >> import java.lang.reflect.Field;
>> >> >> >> import java.lang.reflect.Method;
>> >> >> >> import java.lang.annotation.Annotation;
>> >> >> >> import java.lang.reflect.AnnotatedElement;
>> >> >> >>
>> >> >> >> import org.hibernate.validator.NotNull;
>> >> >> >> import org.hibernate.validator.Length;
>> >> >> >> import org.hibernate.validator.NotEmpty;
>> >> >> >> import org.hibernate.validator.Min;
>> >> >> >> import org.hibernate.validator.Pattern;
>> >> >> >> import org.hibernate.validator.Max;
>> >> >> >> import org.hibernate.validator.Range;
>> >> >> >> import org.hibernate.validator.Past;
>> >> >> >> import org.hibernate.validator.Future;
>> >> >> >> import org.hibernate.validator.Email;
>> >> >> >> import org.hibernate.validator.CreditCardNumber;
>> >> >> >>
>> >> >> >> import org.apache.wicket.validation.validator.StringValidator;
>> >> >> >> import org.apache.wicket.validation.validator.PatternValidator;
>> >> >> >> import org.apache.wicket.validation.validator.NumberValidator;
>> >> >> >> import
>> org.apache.wicket.validation.validator.EmailAddressValidator;
>> >> >> >> import org.apache.wicket.validation.validator.CreditCardValidator;
>> >> >> >> import org.apache.wicket.validation.validator.DateValidator;
>> >> >> >>
>> >> >> >> import org.hibernate.validator.ClassValidator;
>> >> >> >> import org.hibernate.validator.InvalidValue;
>> >> >> >> import org.apache.wicket.behavior.AbstractBehavior;
>> >> >> >> import
>> >> org.apache.wicket.application.IComponentOnBeforeRenderListener;
>> >> >> >> import
>> org.apache.wicket.application.IComponentInstantiationListener;
>> >> >> >> import org.apache.wicket.Component;
>> >> >> >> import org.apache.wicket.markup.Comp

Re: Trying Hibernate Validator Integration

2009-03-14 Thread Will Jaynes
Taha, I've tried playing with  your HibernateValidator. It seems necessary
to add it to each form field. If I add it simply to the form, the validation
behavior doesn't happen. Am I missing something?
Will

On Sat, Mar 14, 2009 at 9:06 AM, taha siddiqi  wrote:

> I was myself very much interested and finally I found
>
> wicket-hibernate at
>
> http://www.jroller.com/wireframe/entry/hibernateannotationcomponentconfigurator
>
> and wicket-jpa at
> http://perfbench.googlecode.com/svn/trunk/perfbench/wicket-jpa/
>
> Then I came up which something that works for me ( already in the post )
>
> taha
>
>
> On Sat, Mar 14, 2009 at 6:16 PM, Will Jaynes  wrote:
> > In the archives, back in 2007, I see a lot of discussion about
> Hibernate/JPA
> > validator and Wicket, but I can't find if there was any result from those
> > discussions. Did anything come of it?
> >
> > Will
> >
> > On Tue, Mar 10, 2009 at 11:29 AM, taha siddiqi  >wrote:
> >
> >> but then how to get a ResourceBundle from wicket resource ??
> >>
> >>
> >> On Tue, Mar 10, 2009 at 8:43 PM, Peter Thomas 
> wrote:
> >> > On Tue, Mar 10, 2009 at 9:04 AM, taha siddiqi 
> >> wrote:
> >> >
> >> >> But the problem is when you begin to use the wicket resource files,
> >> >> hibernate-validator comes with its own messages and need to be
> >> >> integrated with wicket ( which i was not able to )
> >> >
> >> >
> >> > There is some info here on how to pass a resource-bundle to the
> >> > ClassValidator constructor, I haven't tried it though:
> >> >
> >> >
> http://www.jboss.org/index.html?module=bb&op=viewtopic&t=69783&view=next
> >> >
> >> >
> >> >>
> >> >>
> >> >> taha
> >> >>
> >> >> On Tue, Mar 10, 2009 at 8:11 PM, Peter Thomas 
> >> wrote:
> >> >> > On Tue, Mar 10, 2009 at 7:35 AM, taha siddiqi <
> tawushaf...@gmail.com>
> >> >> wrote:
> >> >> >
> >> >> >> Hi,
> >> >> >>
> >> >> >> I was working with Hibernate-validator and thought of sharing the
> >> code.
> >> >> >>
> >> >> >
> >> >> > Taha: I thought the ClassValidator will handle all the different
> cases
> >> >> and
> >> >> > annotations for you, see line #89
> >> >> >
> >> >> >
> >> >>
> >>
> http://code.google.com/p/perfbench/source/browse/trunk/perfbench/wicket-jpa/src/main/java/wicketjpa/wicket/EditBorder.java#89
> >> >> >
> >> >> > Is there any advantage of mapping each type (e.g. Min, Max,
> >> >> > CreditCardNumber) to Wicket built-in validators ?
> >> >> >
> >> >> >
> >> >> >>
> >> >> >> It is a listener as well as a behavior which can be used at
> >> >> >> application level as well as with individual
> >> >> >> components.
> >> >> >>
> >> >> >> It is heavily inspired from wicket-jpa and wicket-hibernate
> >> >> >> projects... I just tried some changes...
> >> >> >>
> >> >> >> import java.util.Map;
> >> >> >> import java.util.Arrays;
> >> >> >> import java.util.List;
> >> >> >> import java.util.Date;
> >> >> >> import java.util.concurrent.ConcurrentHashMap;
> >> >> >> import javax.persistence.Entity;
> >> >> >> import javax.persistence.Embeddable;
> >> >> >> import java.lang.reflect.Field;
> >> >> >> import java.lang.reflect.Method;
> >> >> >> import java.lang.annotation.Annotation;
> >> >> >> import java.lang.reflect.AnnotatedElement;
> >> >> >>
> >> >> >> import org.hibernate.validator.NotNull;
> >> >> >> import org.hibernate.validator.Length;
> >> >> >> import org.hibernate.validator.NotEmpty;
> >> >> >> import org.hibernate.validator.Min;
> >> >> >> import org.hibernate.validator.Pattern;
> >> >> >> import org.hibernate.validator.Max;
> >> >> >> import org.hibernate.validator.Range;
> >> >> >> import org.hibernate.validator.Past;
> >> >> >> import org.hibernate.validator.Future;
> >> >> >> import org.hibernate.validator.Email;
> >> >> >> import org.hibernate.validator.CreditCardNumber;
> >> >> >>
> >> >> >> import org.apache.wicket.validation.validator.StringValidator;
> >> >> >> import org.apache.wicket.validation.validator.PatternValidator;
> >> >> >> import org.apache.wicket.validation.validator.NumberValidator;
> >> >> >> import
> org.apache.wicket.validation.validator.EmailAddressValidator;
> >> >> >> import org.apache.wicket.validation.validator.CreditCardValidator;
> >> >> >> import org.apache.wicket.validation.validator.DateValidator;
> >> >> >>
> >> >> >> import org.hibernate.validator.ClassValidator;
> >> >> >> import org.hibernate.validator.InvalidValue;
> >> >> >> import org.apache.wicket.behavior.AbstractBehavior;
> >> >> >> import
> >> org.apache.wicket.application.IComponentOnBeforeRenderListener;
> >> >> >> import
> org.apache.wicket.application.IComponentInstantiationListener;
> >> >> >> import org.apache.wicket.Component;
> >> >> >> import org.apache.wicket.markup.ComponentTag;
> >> >> >> import org.apache.wicket.feedback.FeedbackMessage;
> >> >> >> import org.apache.wicket.validation.IValidator;
> >> >> >> import org.apache.wicket.validation.IValidatable;
> >> >> >> import org.apache.wicket.model.IModel;
> >> >> >> import org.apache.wicket.model.CompoundPropertyModel;
> >> >> 

Re: Trying Hibernate Validator Integration

2009-03-14 Thread taha siddiqi
I was myself very much interested and finally I found

wicket-hibernate at
http://www.jroller.com/wireframe/entry/hibernateannotationcomponentconfigurator

and wicket-jpa at
http://perfbench.googlecode.com/svn/trunk/perfbench/wicket-jpa/

Then I came up which something that works for me ( already in the post )

taha


On Sat, Mar 14, 2009 at 6:16 PM, Will Jaynes  wrote:
> In the archives, back in 2007, I see a lot of discussion about Hibernate/JPA
> validator and Wicket, but I can't find if there was any result from those
> discussions. Did anything come of it?
>
> Will
>
> On Tue, Mar 10, 2009 at 11:29 AM, taha siddiqi wrote:
>
>> but then how to get a ResourceBundle from wicket resource ??
>>
>>
>> On Tue, Mar 10, 2009 at 8:43 PM, Peter Thomas  wrote:
>> > On Tue, Mar 10, 2009 at 9:04 AM, taha siddiqi 
>> wrote:
>> >
>> >> But the problem is when you begin to use the wicket resource files,
>> >> hibernate-validator comes with its own messages and need to be
>> >> integrated with wicket ( which i was not able to )
>> >
>> >
>> > There is some info here on how to pass a resource-bundle to the
>> > ClassValidator constructor, I haven't tried it though:
>> >
>> > http://www.jboss.org/index.html?module=bb&op=viewtopic&t=69783&view=next
>> >
>> >
>> >>
>> >>
>> >> taha
>> >>
>> >> On Tue, Mar 10, 2009 at 8:11 PM, Peter Thomas 
>> wrote:
>> >> > On Tue, Mar 10, 2009 at 7:35 AM, taha siddiqi 
>> >> wrote:
>> >> >
>> >> >> Hi,
>> >> >>
>> >> >> I was working with Hibernate-validator and thought of sharing the
>> code.
>> >> >>
>> >> >
>> >> > Taha: I thought the ClassValidator will handle all the different cases
>> >> and
>> >> > annotations for you, see line #89
>> >> >
>> >> >
>> >>
>> http://code.google.com/p/perfbench/source/browse/trunk/perfbench/wicket-jpa/src/main/java/wicketjpa/wicket/EditBorder.java#89
>> >> >
>> >> > Is there any advantage of mapping each type (e.g. Min, Max,
>> >> > CreditCardNumber) to Wicket built-in validators ?
>> >> >
>> >> >
>> >> >>
>> >> >> It is a listener as well as a behavior which can be used at
>> >> >> application level as well as with individual
>> >> >> components.
>> >> >>
>> >> >> It is heavily inspired from wicket-jpa and wicket-hibernate
>> >> >> projects... I just tried some changes...
>> >> >>
>> >> >> import java.util.Map;
>> >> >> import java.util.Arrays;
>> >> >> import java.util.List;
>> >> >> import java.util.Date;
>> >> >> import java.util.concurrent.ConcurrentHashMap;
>> >> >> import javax.persistence.Entity;
>> >> >> import javax.persistence.Embeddable;
>> >> >> import java.lang.reflect.Field;
>> >> >> import java.lang.reflect.Method;
>> >> >> import java.lang.annotation.Annotation;
>> >> >> import java.lang.reflect.AnnotatedElement;
>> >> >>
>> >> >> import org.hibernate.validator.NotNull;
>> >> >> import org.hibernate.validator.Length;
>> >> >> import org.hibernate.validator.NotEmpty;
>> >> >> import org.hibernate.validator.Min;
>> >> >> import org.hibernate.validator.Pattern;
>> >> >> import org.hibernate.validator.Max;
>> >> >> import org.hibernate.validator.Range;
>> >> >> import org.hibernate.validator.Past;
>> >> >> import org.hibernate.validator.Future;
>> >> >> import org.hibernate.validator.Email;
>> >> >> import org.hibernate.validator.CreditCardNumber;
>> >> >>
>> >> >> import org.apache.wicket.validation.validator.StringValidator;
>> >> >> import org.apache.wicket.validation.validator.PatternValidator;
>> >> >> import org.apache.wicket.validation.validator.NumberValidator;
>> >> >> import org.apache.wicket.validation.validator.EmailAddressValidator;
>> >> >> import org.apache.wicket.validation.validator.CreditCardValidator;
>> >> >> import org.apache.wicket.validation.validator.DateValidator;
>> >> >>
>> >> >> import org.hibernate.validator.ClassValidator;
>> >> >> import org.hibernate.validator.InvalidValue;
>> >> >> import org.apache.wicket.behavior.AbstractBehavior;
>> >> >> import
>> org.apache.wicket.application.IComponentOnBeforeRenderListener;
>> >> >> import org.apache.wicket.application.IComponentInstantiationListener;
>> >> >> import org.apache.wicket.Component;
>> >> >> import org.apache.wicket.markup.ComponentTag;
>> >> >> import org.apache.wicket.feedback.FeedbackMessage;
>> >> >> import org.apache.wicket.validation.IValidator;
>> >> >> import org.apache.wicket.validation.IValidatable;
>> >> >> import org.apache.wicket.model.IModel;
>> >> >> import org.apache.wicket.model.CompoundPropertyModel;
>> >> >> import org.apache.wicket.markup.html.form.FormComponent;
>> >> >> import org.apache.wicket.validation.ValidationError;
>> >> >> import org.apache.wicket.validation.validator.StringValidator;
>> >> >> import org.apache.wicket.AttributeModifier;
>> >> >> import org.apache.wicket.model.Model;
>> >> >> import org.slf4j.Logger;
>> >> >> import org.slf4j.LoggerFactory;
>> >> >>
>> >> >> /**
>> >> >>  * A validator to validate elements having
>> >> >>  * hibernate validators annotated.
>> >> >>  */
>> >> >> public class HibernateValidator

Re: Trying Hibernate Validator Integration

2009-03-14 Thread Will Jaynes
In the archives, back in 2007, I see a lot of discussion about Hibernate/JPA
validator and Wicket, but I can't find if there was any result from those
discussions. Did anything come of it?

Will

On Tue, Mar 10, 2009 at 11:29 AM, taha siddiqi wrote:

> but then how to get a ResourceBundle from wicket resource ??
>
>
> On Tue, Mar 10, 2009 at 8:43 PM, Peter Thomas  wrote:
> > On Tue, Mar 10, 2009 at 9:04 AM, taha siddiqi 
> wrote:
> >
> >> But the problem is when you begin to use the wicket resource files,
> >> hibernate-validator comes with its own messages and need to be
> >> integrated with wicket ( which i was not able to )
> >
> >
> > There is some info here on how to pass a resource-bundle to the
> > ClassValidator constructor, I haven't tried it though:
> >
> > http://www.jboss.org/index.html?module=bb&op=viewtopic&t=69783&view=next
> >
> >
> >>
> >>
> >> taha
> >>
> >> On Tue, Mar 10, 2009 at 8:11 PM, Peter Thomas 
> wrote:
> >> > On Tue, Mar 10, 2009 at 7:35 AM, taha siddiqi 
> >> wrote:
> >> >
> >> >> Hi,
> >> >>
> >> >> I was working with Hibernate-validator and thought of sharing the
> code.
> >> >>
> >> >
> >> > Taha: I thought the ClassValidator will handle all the different cases
> >> and
> >> > annotations for you, see line #89
> >> >
> >> >
> >>
> http://code.google.com/p/perfbench/source/browse/trunk/perfbench/wicket-jpa/src/main/java/wicketjpa/wicket/EditBorder.java#89
> >> >
> >> > Is there any advantage of mapping each type (e.g. Min, Max,
> >> > CreditCardNumber) to Wicket built-in validators ?
> >> >
> >> >
> >> >>
> >> >> It is a listener as well as a behavior which can be used at
> >> >> application level as well as with individual
> >> >> components.
> >> >>
> >> >> It is heavily inspired from wicket-jpa and wicket-hibernate
> >> >> projects... I just tried some changes...
> >> >>
> >> >> import java.util.Map;
> >> >> import java.util.Arrays;
> >> >> import java.util.List;
> >> >> import java.util.Date;
> >> >> import java.util.concurrent.ConcurrentHashMap;
> >> >> import javax.persistence.Entity;
> >> >> import javax.persistence.Embeddable;
> >> >> import java.lang.reflect.Field;
> >> >> import java.lang.reflect.Method;
> >> >> import java.lang.annotation.Annotation;
> >> >> import java.lang.reflect.AnnotatedElement;
> >> >>
> >> >> import org.hibernate.validator.NotNull;
> >> >> import org.hibernate.validator.Length;
> >> >> import org.hibernate.validator.NotEmpty;
> >> >> import org.hibernate.validator.Min;
> >> >> import org.hibernate.validator.Pattern;
> >> >> import org.hibernate.validator.Max;
> >> >> import org.hibernate.validator.Range;
> >> >> import org.hibernate.validator.Past;
> >> >> import org.hibernate.validator.Future;
> >> >> import org.hibernate.validator.Email;
> >> >> import org.hibernate.validator.CreditCardNumber;
> >> >>
> >> >> import org.apache.wicket.validation.validator.StringValidator;
> >> >> import org.apache.wicket.validation.validator.PatternValidator;
> >> >> import org.apache.wicket.validation.validator.NumberValidator;
> >> >> import org.apache.wicket.validation.validator.EmailAddressValidator;
> >> >> import org.apache.wicket.validation.validator.CreditCardValidator;
> >> >> import org.apache.wicket.validation.validator.DateValidator;
> >> >>
> >> >> import org.hibernate.validator.ClassValidator;
> >> >> import org.hibernate.validator.InvalidValue;
> >> >> import org.apache.wicket.behavior.AbstractBehavior;
> >> >> import
> org.apache.wicket.application.IComponentOnBeforeRenderListener;
> >> >> import org.apache.wicket.application.IComponentInstantiationListener;
> >> >> import org.apache.wicket.Component;
> >> >> import org.apache.wicket.markup.ComponentTag;
> >> >> import org.apache.wicket.feedback.FeedbackMessage;
> >> >> import org.apache.wicket.validation.IValidator;
> >> >> import org.apache.wicket.validation.IValidatable;
> >> >> import org.apache.wicket.model.IModel;
> >> >> import org.apache.wicket.model.CompoundPropertyModel;
> >> >> import org.apache.wicket.markup.html.form.FormComponent;
> >> >> import org.apache.wicket.validation.ValidationError;
> >> >> import org.apache.wicket.validation.validator.StringValidator;
> >> >> import org.apache.wicket.AttributeModifier;
> >> >> import org.apache.wicket.model.Model;
> >> >> import org.slf4j.Logger;
> >> >> import org.slf4j.LoggerFactory;
> >> >>
> >> >> /**
> >> >>  * A validator to validate elements having
> >> >>  * hibernate validators annotated.
> >> >>  */
> >> >> public class HibernateValidator extends AbstractBehavior
> >> >>   implements IComponentOnBeforeRenderListener {
> >> >>
> >> >>   private static Logger logger = LoggerFactory.getLogger(
> >> >> HibernateValidator.class );
> >> >>
> >> >>   public final void onBeforeRender( Component c ){
> >> >>  if( !c.hasBeenRendered() ){
> >> >> configure(c);
> >> >>  }
> >> >>   }
> >> >>
> >> >>   @Override
> >> >>   public void beforeRender( Component c ){
> >> >>  super.beforeRender( c );
> >> >>  configure

Re: Trying Hibernate Validator Integration

2009-03-10 Thread taha siddiqi
but then how to get a ResourceBundle from wicket resource ??


On Tue, Mar 10, 2009 at 8:43 PM, Peter Thomas  wrote:
> On Tue, Mar 10, 2009 at 9:04 AM, taha siddiqi  wrote:
>
>> But the problem is when you begin to use the wicket resource files,
>> hibernate-validator comes with its own messages and need to be
>> integrated with wicket ( which i was not able to )
>
>
> There is some info here on how to pass a resource-bundle to the
> ClassValidator constructor, I haven't tried it though:
>
> http://www.jboss.org/index.html?module=bb&op=viewtopic&t=69783&view=next
>
>
>>
>>
>> taha
>>
>> On Tue, Mar 10, 2009 at 8:11 PM, Peter Thomas  wrote:
>> > On Tue, Mar 10, 2009 at 7:35 AM, taha siddiqi 
>> wrote:
>> >
>> >> Hi,
>> >>
>> >> I was working with Hibernate-validator and thought of sharing the code.
>> >>
>> >
>> > Taha: I thought the ClassValidator will handle all the different cases
>> and
>> > annotations for you, see line #89
>> >
>> >
>> http://code.google.com/p/perfbench/source/browse/trunk/perfbench/wicket-jpa/src/main/java/wicketjpa/wicket/EditBorder.java#89
>> >
>> > Is there any advantage of mapping each type (e.g. Min, Max,
>> > CreditCardNumber) to Wicket built-in validators ?
>> >
>> >
>> >>
>> >> It is a listener as well as a behavior which can be used at
>> >> application level as well as with individual
>> >> components.
>> >>
>> >> It is heavily inspired from wicket-jpa and wicket-hibernate
>> >> projects... I just tried some changes...
>> >>
>> >> import java.util.Map;
>> >> import java.util.Arrays;
>> >> import java.util.List;
>> >> import java.util.Date;
>> >> import java.util.concurrent.ConcurrentHashMap;
>> >> import javax.persistence.Entity;
>> >> import javax.persistence.Embeddable;
>> >> import java.lang.reflect.Field;
>> >> import java.lang.reflect.Method;
>> >> import java.lang.annotation.Annotation;
>> >> import java.lang.reflect.AnnotatedElement;
>> >>
>> >> import org.hibernate.validator.NotNull;
>> >> import org.hibernate.validator.Length;
>> >> import org.hibernate.validator.NotEmpty;
>> >> import org.hibernate.validator.Min;
>> >> import org.hibernate.validator.Pattern;
>> >> import org.hibernate.validator.Max;
>> >> import org.hibernate.validator.Range;
>> >> import org.hibernate.validator.Past;
>> >> import org.hibernate.validator.Future;
>> >> import org.hibernate.validator.Email;
>> >> import org.hibernate.validator.CreditCardNumber;
>> >>
>> >> import org.apache.wicket.validation.validator.StringValidator;
>> >> import org.apache.wicket.validation.validator.PatternValidator;
>> >> import org.apache.wicket.validation.validator.NumberValidator;
>> >> import org.apache.wicket.validation.validator.EmailAddressValidator;
>> >> import org.apache.wicket.validation.validator.CreditCardValidator;
>> >> import org.apache.wicket.validation.validator.DateValidator;
>> >>
>> >> import org.hibernate.validator.ClassValidator;
>> >> import org.hibernate.validator.InvalidValue;
>> >> import org.apache.wicket.behavior.AbstractBehavior;
>> >> import org.apache.wicket.application.IComponentOnBeforeRenderListener;
>> >> import org.apache.wicket.application.IComponentInstantiationListener;
>> >> import org.apache.wicket.Component;
>> >> import org.apache.wicket.markup.ComponentTag;
>> >> import org.apache.wicket.feedback.FeedbackMessage;
>> >> import org.apache.wicket.validation.IValidator;
>> >> import org.apache.wicket.validation.IValidatable;
>> >> import org.apache.wicket.model.IModel;
>> >> import org.apache.wicket.model.CompoundPropertyModel;
>> >> import org.apache.wicket.markup.html.form.FormComponent;
>> >> import org.apache.wicket.validation.ValidationError;
>> >> import org.apache.wicket.validation.validator.StringValidator;
>> >> import org.apache.wicket.AttributeModifier;
>> >> import org.apache.wicket.model.Model;
>> >> import org.slf4j.Logger;
>> >> import org.slf4j.LoggerFactory;
>> >>
>> >> /**
>> >>  * A validator to validate elements having
>> >>  * hibernate validators annotated.
>> >>  */
>> >> public class HibernateValidator extends AbstractBehavior
>> >>   implements IComponentOnBeforeRenderListener {
>> >>
>> >>   private static Logger logger = LoggerFactory.getLogger(
>> >> HibernateValidator.class );
>> >>
>> >>   public final void onBeforeRender( Component c ){
>> >>      if( !c.hasBeenRendered() ){
>> >>         configure(c);
>> >>      }
>> >>   }
>> >>
>> >>   @Override
>> >>   public void beforeRender( Component c ){
>> >>      super.beforeRender( c );
>> >>      configure( c );
>> >>   }
>> >>
>> >>   @SuppressWarnings( "unchecked" )
>> >>   private boolean configure( Component c ){
>> >>      if( !isApplicableFor( c ) ){
>> >>         return false;
>> >>      }
>> >>
>> >>      FormComponent fc = (FormComponent)c;
>> >>      CompoundPropertyModel cpm =
>> >>         (CompoundPropertyModel)fc.getInnermostModel();
>> >>
>> >>      Class clazz = cpm.getObject().getClass();
>> >>      if( clazz.isAnnotationPresent( Entity.class ) ||
>> >>          clazz.isAnnotati

Re: Trying Hibernate Validator Integration

2009-03-10 Thread Peter Thomas
On Tue, Mar 10, 2009 at 9:04 AM, taha siddiqi  wrote:

> But the problem is when you begin to use the wicket resource files,
> hibernate-validator comes with its own messages and need to be
> integrated with wicket ( which i was not able to )


There is some info here on how to pass a resource-bundle to the
ClassValidator constructor, I haven't tried it though:

http://www.jboss.org/index.html?module=bb&op=viewtopic&t=69783&view=next


>
>
> taha
>
> On Tue, Mar 10, 2009 at 8:11 PM, Peter Thomas  wrote:
> > On Tue, Mar 10, 2009 at 7:35 AM, taha siddiqi 
> wrote:
> >
> >> Hi,
> >>
> >> I was working with Hibernate-validator and thought of sharing the code.
> >>
> >
> > Taha: I thought the ClassValidator will handle all the different cases
> and
> > annotations for you, see line #89
> >
> >
> http://code.google.com/p/perfbench/source/browse/trunk/perfbench/wicket-jpa/src/main/java/wicketjpa/wicket/EditBorder.java#89
> >
> > Is there any advantage of mapping each type (e.g. Min, Max,
> > CreditCardNumber) to Wicket built-in validators ?
> >
> >
> >>
> >> It is a listener as well as a behavior which can be used at
> >> application level as well as with individual
> >> components.
> >>
> >> It is heavily inspired from wicket-jpa and wicket-hibernate
> >> projects... I just tried some changes...
> >>
> >> import java.util.Map;
> >> import java.util.Arrays;
> >> import java.util.List;
> >> import java.util.Date;
> >> import java.util.concurrent.ConcurrentHashMap;
> >> import javax.persistence.Entity;
> >> import javax.persistence.Embeddable;
> >> import java.lang.reflect.Field;
> >> import java.lang.reflect.Method;
> >> import java.lang.annotation.Annotation;
> >> import java.lang.reflect.AnnotatedElement;
> >>
> >> import org.hibernate.validator.NotNull;
> >> import org.hibernate.validator.Length;
> >> import org.hibernate.validator.NotEmpty;
> >> import org.hibernate.validator.Min;
> >> import org.hibernate.validator.Pattern;
> >> import org.hibernate.validator.Max;
> >> import org.hibernate.validator.Range;
> >> import org.hibernate.validator.Past;
> >> import org.hibernate.validator.Future;
> >> import org.hibernate.validator.Email;
> >> import org.hibernate.validator.CreditCardNumber;
> >>
> >> import org.apache.wicket.validation.validator.StringValidator;
> >> import org.apache.wicket.validation.validator.PatternValidator;
> >> import org.apache.wicket.validation.validator.NumberValidator;
> >> import org.apache.wicket.validation.validator.EmailAddressValidator;
> >> import org.apache.wicket.validation.validator.CreditCardValidator;
> >> import org.apache.wicket.validation.validator.DateValidator;
> >>
> >> import org.hibernate.validator.ClassValidator;
> >> import org.hibernate.validator.InvalidValue;
> >> import org.apache.wicket.behavior.AbstractBehavior;
> >> import org.apache.wicket.application.IComponentOnBeforeRenderListener;
> >> import org.apache.wicket.application.IComponentInstantiationListener;
> >> import org.apache.wicket.Component;
> >> import org.apache.wicket.markup.ComponentTag;
> >> import org.apache.wicket.feedback.FeedbackMessage;
> >> import org.apache.wicket.validation.IValidator;
> >> import org.apache.wicket.validation.IValidatable;
> >> import org.apache.wicket.model.IModel;
> >> import org.apache.wicket.model.CompoundPropertyModel;
> >> import org.apache.wicket.markup.html.form.FormComponent;
> >> import org.apache.wicket.validation.ValidationError;
> >> import org.apache.wicket.validation.validator.StringValidator;
> >> import org.apache.wicket.AttributeModifier;
> >> import org.apache.wicket.model.Model;
> >> import org.slf4j.Logger;
> >> import org.slf4j.LoggerFactory;
> >>
> >> /**
> >>  * A validator to validate elements having
> >>  * hibernate validators annotated.
> >>  */
> >> public class HibernateValidator extends AbstractBehavior
> >>   implements IComponentOnBeforeRenderListener {
> >>
> >>   private static Logger logger = LoggerFactory.getLogger(
> >> HibernateValidator.class );
> >>
> >>   public final void onBeforeRender( Component c ){
> >>  if( !c.hasBeenRendered() ){
> >> configure(c);
> >>  }
> >>   }
> >>
> >>   @Override
> >>   public void beforeRender( Component c ){
> >>  super.beforeRender( c );
> >>  configure( c );
> >>   }
> >>
> >>   @SuppressWarnings( "unchecked" )
> >>   private boolean configure( Component c ){
> >>  if( !isApplicableFor( c ) ){
> >> return false;
> >>  }
> >>
> >>  FormComponent fc = (FormComponent)c;
> >>  CompoundPropertyModel cpm =
> >> (CompoundPropertyModel)fc.getInnermostModel();
> >>
> >>  Class clazz = cpm.getObject().getClass();
> >>  if( clazz.isAnnotationPresent( Entity.class ) ||
> >>  clazz.isAnnotationPresent( Embeddable.class ) ){
> >>
> >> try {
> >>AnnotatedElement element = (AnnotatedElement)
> >>
> >> org.apache.wicket.util.lang.PropertyResolver.getPropertyGetter(
> >>  fc.getId(), cpm.getObject() );
> >>
>

Re: Trying Hibernate Validator Integration

2009-03-10 Thread taha siddiqi
But the problem is when you begin to use the wicket resource files,
hibernate-validator comes with its own messages and need to be
integrated with wicket ( which i was not able to )

taha

On Tue, Mar 10, 2009 at 8:11 PM, Peter Thomas  wrote:
> On Tue, Mar 10, 2009 at 7:35 AM, taha siddiqi  wrote:
>
>> Hi,
>>
>> I was working with Hibernate-validator and thought of sharing the code.
>>
>
> Taha: I thought the ClassValidator will handle all the different cases and
> annotations for you, see line #89
>
> http://code.google.com/p/perfbench/source/browse/trunk/perfbench/wicket-jpa/src/main/java/wicketjpa/wicket/EditBorder.java#89
>
> Is there any advantage of mapping each type (e.g. Min, Max,
> CreditCardNumber) to Wicket built-in validators ?
>
>
>>
>> It is a listener as well as a behavior which can be used at
>> application level as well as with individual
>> components.
>>
>> It is heavily inspired from wicket-jpa and wicket-hibernate
>> projects... I just tried some changes...
>>
>> import java.util.Map;
>> import java.util.Arrays;
>> import java.util.List;
>> import java.util.Date;
>> import java.util.concurrent.ConcurrentHashMap;
>> import javax.persistence.Entity;
>> import javax.persistence.Embeddable;
>> import java.lang.reflect.Field;
>> import java.lang.reflect.Method;
>> import java.lang.annotation.Annotation;
>> import java.lang.reflect.AnnotatedElement;
>>
>> import org.hibernate.validator.NotNull;
>> import org.hibernate.validator.Length;
>> import org.hibernate.validator.NotEmpty;
>> import org.hibernate.validator.Min;
>> import org.hibernate.validator.Pattern;
>> import org.hibernate.validator.Max;
>> import org.hibernate.validator.Range;
>> import org.hibernate.validator.Past;
>> import org.hibernate.validator.Future;
>> import org.hibernate.validator.Email;
>> import org.hibernate.validator.CreditCardNumber;
>>
>> import org.apache.wicket.validation.validator.StringValidator;
>> import org.apache.wicket.validation.validator.PatternValidator;
>> import org.apache.wicket.validation.validator.NumberValidator;
>> import org.apache.wicket.validation.validator.EmailAddressValidator;
>> import org.apache.wicket.validation.validator.CreditCardValidator;
>> import org.apache.wicket.validation.validator.DateValidator;
>>
>> import org.hibernate.validator.ClassValidator;
>> import org.hibernate.validator.InvalidValue;
>> import org.apache.wicket.behavior.AbstractBehavior;
>> import org.apache.wicket.application.IComponentOnBeforeRenderListener;
>> import org.apache.wicket.application.IComponentInstantiationListener;
>> import org.apache.wicket.Component;
>> import org.apache.wicket.markup.ComponentTag;
>> import org.apache.wicket.feedback.FeedbackMessage;
>> import org.apache.wicket.validation.IValidator;
>> import org.apache.wicket.validation.IValidatable;
>> import org.apache.wicket.model.IModel;
>> import org.apache.wicket.model.CompoundPropertyModel;
>> import org.apache.wicket.markup.html.form.FormComponent;
>> import org.apache.wicket.validation.ValidationError;
>> import org.apache.wicket.validation.validator.StringValidator;
>> import org.apache.wicket.AttributeModifier;
>> import org.apache.wicket.model.Model;
>> import org.slf4j.Logger;
>> import org.slf4j.LoggerFactory;
>>
>> /**
>>  * A validator to validate elements having
>>  * hibernate validators annotated.
>>  */
>> public class HibernateValidator extends AbstractBehavior
>>   implements IComponentOnBeforeRenderListener {
>>
>>   private static Logger logger = LoggerFactory.getLogger(
>> HibernateValidator.class );
>>
>>   public final void onBeforeRender( Component c ){
>>      if( !c.hasBeenRendered() ){
>>         configure(c);
>>      }
>>   }
>>
>>   @Override
>>   public void beforeRender( Component c ){
>>      super.beforeRender( c );
>>      configure( c );
>>   }
>>
>>   @SuppressWarnings( "unchecked" )
>>   private boolean configure( Component c ){
>>      if( !isApplicableFor( c ) ){
>>         return false;
>>      }
>>
>>      FormComponent fc = (FormComponent)c;
>>      CompoundPropertyModel cpm =
>>         (CompoundPropertyModel)fc.getInnermostModel();
>>
>>      Class clazz = cpm.getObject().getClass();
>>      if( clazz.isAnnotationPresent( Entity.class ) ||
>>          clazz.isAnnotationPresent( Embeddable.class ) ){
>>
>>         try {
>>            AnnotatedElement element = (AnnotatedElement)
>>
>> org.apache.wicket.util.lang.PropertyResolver.getPropertyGetter(
>>                  fc.getId(), cpm.getObject() );
>>
>>            addValidator( fc, element );
>>         }catch( Exception ex ){
>>         }
>>      }
>>
>>      return true;
>>   }
>>
>>   protected void addValidator( FormComponent fc, AnnotatedElement element
>> ){
>>      //@NotNull
>>      if( element.isAnnotationPresent( NotNull.class ) ||
>>          element.isAnnotationPresent( NotEmpty.class ) ){
>>         fc.setRequired( true );
>>      }
>>
>>      //@Length( min, max )
>>      if( element.isAnnotationPresent( Length.class ) ){
>>         L

Re: Trying Hibernate Validator Integration

2009-03-10 Thread Peter Thomas
On Tue, Mar 10, 2009 at 7:35 AM, taha siddiqi  wrote:

> Hi,
>
> I was working with Hibernate-validator and thought of sharing the code.
>

Taha: I thought the ClassValidator will handle all the different cases and
annotations for you, see line #89

http://code.google.com/p/perfbench/source/browse/trunk/perfbench/wicket-jpa/src/main/java/wicketjpa/wicket/EditBorder.java#89

Is there any advantage of mapping each type (e.g. Min, Max,
CreditCardNumber) to Wicket built-in validators ?


>
> It is a listener as well as a behavior which can be used at
> application level as well as with individual
> components.
>
> It is heavily inspired from wicket-jpa and wicket-hibernate
> projects... I just tried some changes...
>
> import java.util.Map;
> import java.util.Arrays;
> import java.util.List;
> import java.util.Date;
> import java.util.concurrent.ConcurrentHashMap;
> import javax.persistence.Entity;
> import javax.persistence.Embeddable;
> import java.lang.reflect.Field;
> import java.lang.reflect.Method;
> import java.lang.annotation.Annotation;
> import java.lang.reflect.AnnotatedElement;
>
> import org.hibernate.validator.NotNull;
> import org.hibernate.validator.Length;
> import org.hibernate.validator.NotEmpty;
> import org.hibernate.validator.Min;
> import org.hibernate.validator.Pattern;
> import org.hibernate.validator.Max;
> import org.hibernate.validator.Range;
> import org.hibernate.validator.Past;
> import org.hibernate.validator.Future;
> import org.hibernate.validator.Email;
> import org.hibernate.validator.CreditCardNumber;
>
> import org.apache.wicket.validation.validator.StringValidator;
> import org.apache.wicket.validation.validator.PatternValidator;
> import org.apache.wicket.validation.validator.NumberValidator;
> import org.apache.wicket.validation.validator.EmailAddressValidator;
> import org.apache.wicket.validation.validator.CreditCardValidator;
> import org.apache.wicket.validation.validator.DateValidator;
>
> import org.hibernate.validator.ClassValidator;
> import org.hibernate.validator.InvalidValue;
> import org.apache.wicket.behavior.AbstractBehavior;
> import org.apache.wicket.application.IComponentOnBeforeRenderListener;
> import org.apache.wicket.application.IComponentInstantiationListener;
> import org.apache.wicket.Component;
> import org.apache.wicket.markup.ComponentTag;
> import org.apache.wicket.feedback.FeedbackMessage;
> import org.apache.wicket.validation.IValidator;
> import org.apache.wicket.validation.IValidatable;
> import org.apache.wicket.model.IModel;
> import org.apache.wicket.model.CompoundPropertyModel;
> import org.apache.wicket.markup.html.form.FormComponent;
> import org.apache.wicket.validation.ValidationError;
> import org.apache.wicket.validation.validator.StringValidator;
> import org.apache.wicket.AttributeModifier;
> import org.apache.wicket.model.Model;
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> /**
>  * A validator to validate elements having
>  * hibernate validators annotated.
>  */
> public class HibernateValidator extends AbstractBehavior
>   implements IComponentOnBeforeRenderListener {
>
>   private static Logger logger = LoggerFactory.getLogger(
> HibernateValidator.class );
>
>   public final void onBeforeRender( Component c ){
>  if( !c.hasBeenRendered() ){
> configure(c);
>  }
>   }
>
>   @Override
>   public void beforeRender( Component c ){
>  super.beforeRender( c );
>  configure( c );
>   }
>
>   @SuppressWarnings( "unchecked" )
>   private boolean configure( Component c ){
>  if( !isApplicableFor( c ) ){
> return false;
>  }
>
>  FormComponent fc = (FormComponent)c;
>  CompoundPropertyModel cpm =
> (CompoundPropertyModel)fc.getInnermostModel();
>
>  Class clazz = cpm.getObject().getClass();
>  if( clazz.isAnnotationPresent( Entity.class ) ||
>  clazz.isAnnotationPresent( Embeddable.class ) ){
>
> try {
>AnnotatedElement element = (AnnotatedElement)
>
> org.apache.wicket.util.lang.PropertyResolver.getPropertyGetter(
>  fc.getId(), cpm.getObject() );
>
>addValidator( fc, element );
> }catch( Exception ex ){
> }
>  }
>
>  return true;
>   }
>
>   protected void addValidator( FormComponent fc, AnnotatedElement element
> ){
>  //@NotNull
>  if( element.isAnnotationPresent( NotNull.class ) ||
>  element.isAnnotationPresent( NotEmpty.class ) ){
> fc.setRequired( true );
>  }
>
>  //@Length( min, max )
>  if( element.isAnnotationPresent( Length.class ) ){
> Length l = element.getAnnotation( Length.class );
>
> if( l.min() == 0 && l.max() < Integer.MAX_VALUE ){ //TODO:
> replace with max int
>fc.add( StringValidator.maximumLength( l.max() ) );
> }else if( l.min() != 0 && l.max() < Integer.MAX_VALUE ){
>fc.add( StringValidator.lengthBetween( l.min(), l.max() ) );
> }else if( l.min() != 0 && 

Trying Hibernate Validator Integration

2009-03-10 Thread taha siddiqi
Hi,

I was working with Hibernate-validator and thought of sharing the code.

It is a listener as well as a behavior which can be used at
application level as well as with individual
components.

It is heavily inspired from wicket-jpa and wicket-hibernate
projects... I just tried some changes...

import java.util.Map;
import java.util.Arrays;
import java.util.List;
import java.util.Date;
import java.util.concurrent.ConcurrentHashMap;
import javax.persistence.Entity;
import javax.persistence.Embeddable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;

import org.hibernate.validator.NotNull;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotEmpty;
import org.hibernate.validator.Min;
import org.hibernate.validator.Pattern;
import org.hibernate.validator.Max;
import org.hibernate.validator.Range;
import org.hibernate.validator.Past;
import org.hibernate.validator.Future;
import org.hibernate.validator.Email;
import org.hibernate.validator.CreditCardNumber;

import org.apache.wicket.validation.validator.StringValidator;
import org.apache.wicket.validation.validator.PatternValidator;
import org.apache.wicket.validation.validator.NumberValidator;
import org.apache.wicket.validation.validator.EmailAddressValidator;
import org.apache.wicket.validation.validator.CreditCardValidator;
import org.apache.wicket.validation.validator.DateValidator;

import org.hibernate.validator.ClassValidator;
import org.hibernate.validator.InvalidValue;
import org.apache.wicket.behavior.AbstractBehavior;
import org.apache.wicket.application.IComponentOnBeforeRenderListener;
import org.apache.wicket.application.IComponentInstantiationListener;
import org.apache.wicket.Component;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.feedback.FeedbackMessage;
import org.apache.wicket.validation.IValidator;
import org.apache.wicket.validation.IValidatable;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.validation.ValidationError;
import org.apache.wicket.validation.validator.StringValidator;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.model.Model;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A validator to validate elements having
 * hibernate validators annotated.
 */
public class HibernateValidator extends AbstractBehavior
   implements IComponentOnBeforeRenderListener {

   private static Logger logger = LoggerFactory.getLogger(
HibernateValidator.class );

   public final void onBeforeRender( Component c ){
  if( !c.hasBeenRendered() ){
 configure(c);
  }
   }

   @Override
   public void beforeRender( Component c ){
  super.beforeRender( c );
  configure( c );
   }

   @SuppressWarnings( "unchecked" )
   private boolean configure( Component c ){
  if( !isApplicableFor( c ) ){
 return false;
  }

  FormComponent fc = (FormComponent)c;
  CompoundPropertyModel cpm =
 (CompoundPropertyModel)fc.getInnermostModel();

  Class clazz = cpm.getObject().getClass();
  if( clazz.isAnnotationPresent( Entity.class ) ||
  clazz.isAnnotationPresent( Embeddable.class ) ){

 try {
AnnotatedElement element = (AnnotatedElement)
   org.apache.wicket.util.lang.PropertyResolver.getPropertyGetter(
  fc.getId(), cpm.getObject() );

addValidator( fc, element );
 }catch( Exception ex ){
 }
  }

  return true;
   }

   protected void addValidator( FormComponent fc, AnnotatedElement element ){
  //@NotNull
  if( element.isAnnotationPresent( NotNull.class ) ||
  element.isAnnotationPresent( NotEmpty.class ) ){
 fc.setRequired( true );
  }

  //@Length( min, max )
  if( element.isAnnotationPresent( Length.class ) ){
 Length l = element.getAnnotation( Length.class );

 if( l.min() == 0 && l.max() < Integer.MAX_VALUE ){ //TODO:
replace with max int
fc.add( StringValidator.maximumLength( l.max() ) );
 }else if( l.min() != 0 && l.max() < Integer.MAX_VALUE ){
fc.add( StringValidator.lengthBetween( l.min(), l.max() ) );
 }else if( l.min() != 0 && l.max() >= Integer.MAX_VALUE ){
fc.add( StringValidator.minimumLength( l.min() ) );
 }
  }

  //@Max( value )
  if( element.isAnnotationPresent( Max.class ) ){
 Max max = element.getAnnotation( Max.class );
 fc.add( NumberValidator.maximum( max.value() ) );
  }

  //@Min( value )
  if( element.isAnnotationPresent( Min.class ) ){
 Min min = element.getAnnotation( Min.class );
 fc.add( NumberValidator.minimum( min.value() ) );
  }

  //@Range( min, max )
  if( element.isAnnotationPresent( Range.