-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: LocalValidatorFactoryBean bootstrap and ConstraintMapping's
PostPosted: Tue Jan 10, 2012 6:09 pm 
Newbie

Joined: Tue Jul 05, 2011 7:28 am
Posts: 10
Hi guys,

I am using Spring 3.0.5 and Hibernate Validator 4.2.0 in my webapp. All is working well and I use the LocalValidatorFactoryBean bean to perform the Validator bootstrapping/initialization.

JavaDoc - http://static.springsource.org/spring/d ... yBean.html

Code - http://javasourcecode.org/html/open-sou ... .java.html

Hibernate Validator also defines a programmatic API to define constraints which is outside of the JSR-303 specification. From reading the documentation you need to add the ConstraintMapping's during the bootstrap process before the Validator is created. I don't see an obvious way of extending the LocalValidatorFactoryBean to do this in the afterPropertiesSet method which is doing the Validator bootstrapping at the moment. Ideally I'd like to able to add ConstraintMapping's via XML application context configuration in something like the same way that is done for the mappingLocations.

Any ideas would be greatly appreciated. I have tried the Spring forum's but no luck there.

Thanks,
Mark


Top
 Profile  
 
 Post subject: Re: LocalValidatorFactoryBean bootstrap and ConstraintMapping's
PostPosted: Wed Jan 11, 2012 6:13 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

generally the bootstrapping looks like this:

Code:
HibernateValidatorConfiguration config = Validation.byProvider( HibernateValidator.class ).configure();
config.addMapping( mapping );
ValidatorFactory factory = config.buildValidatorFactory();
Validator validator = factory.getValidator();


I don't know much about the Spring integration and looking only at LocalValidatorFactoryBean it is hard to be very specific. The class is written to bootstrap any provider really. So if you want to use the programmatic approach you would need to somehow check and cast the Configuration to HibernateValidatorConfiguration. LocalValidatorFactoryBean seems to get passes the whole ApplicationContext so you should be able to retrieve the constraint mapping from there. Maybe you could override afterPropertiesSet. That's only an idea. I am not sure how LocalValidatorFactoryBean comes into play and whether you can easily replace it with your own version.

--Hardy


Top
 Profile  
 
 Post subject: Re: LocalValidatorFactoryBean bootstrap and ConstraintMapping's
PostPosted: Wed Jan 11, 2012 1:10 pm 
Newbie

Joined: Tue Jul 05, 2011 7:28 am
Posts: 10
Thanks Hardy for your input.

My conclusion is the same as yours in that I will have to override the afterPropertiesSet method to put in the logic to add the ConstraintMapping's during the bootstrap process. What I will probably do is create my own version of LocalValidatorFactoryBean and call it HibernateValidatorFactoryBean which I can then configure in my Spring ApplicationContext XML file. Therefore changing between either bootstrap process is simply a 1 line change to an XML config file.

Thanks,
Mark


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.