-->
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.  [ 2 posts ] 
Author Message
 Post subject: validator with many validation.xml file ???
PostPosted: Thu Feb 04, 2010 6:08 pm 
Newbie

Joined: Mon Jan 18, 2010 12:32 pm
Posts: 2
Hi Hibernate validator community,

I want to know how can i use different validator for the same object. Let's say i have a Employee class to validate and i want to validate it with different ways. For example, for a HR employee, i want to validate it based on the fact that the HR person can set any type of employee to the object while a Director employee can only set "normal" type for an Employee object.

I want to be able to use many validation.xml files based on a condition that is only decided at runtime. Is is possible ?


Top
 Profile  
 
 Post subject: Re: validator with many validation.xml file ???
PostPosted: Fri Feb 05, 2010 10:40 am 
Hibernate Team
Hibernate Team

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

validation.xml is not really an option here. The spec says:
Quote:
If more than one META-INF/validation.xml file is
found in the classpath, a ValidationException is raised.


You could programmatically create multiple ValidatorFactorys and have multiple Validators. I don't think I would recommend this approach though. I probably would write a custom constraint where in the ConstraintValidator implementation I act depending on the user logged in. Or maybe you could use groups. Assign you constraints to groups (eg HS group and Director group), then when you call Validator.validate only validate the group depending on the logged in person. This is probably the best solution.

--Hardy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.