-->
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.  [ 4 posts ] 
Author Message
 Post subject: Locale based validation
PostPosted: Fri May 28, 2010 7:25 am 
Newbie

Joined: Fri May 28, 2010 7:01 am
Posts: 2
Hi ,

My project have two main requirements

1) Different set of rules applied to same object at insertion and while updating it.

2) Different validation rules based on locale.

In ADDRESS object STATE field requires different validation rules
For USA: STATE cannot be NULL.
For everywhere else it can be NULL.



For first requirement i am already using GROUPS.
Is there a way to achieve second requirements.

I am using:
Hibernate Validator 4.0.1 GA
Hibernate 5.2.6


Top
 Profile  
 
 Post subject: Re: Locale based validation
PostPosted: Fri May 28, 2010 10:01 am 
Hibernate Team
Hibernate Team

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

have you thought about writing a custom constraint(s). Either on field or on class level. For example you could have a @AddessConstraint which validates an address object taking the LOCALE into consideration.

--Hardy


Top
 Profile  
 
 Post subject: Re: Locale based validation
PostPosted: Fri May 28, 2010 3:22 pm 
Newbie

Joined: Fri May 28, 2010 7:01 am
Posts: 2
Thanks Hardy. But isn't there any kind of support in the framework for localized validations. Like different validation xml files for each region ( mechanism similar to language properties files i.e messages.properties , messages_fr.properties etc ). Or anything like multiple group options ( a group with in a group or something of this sort ).

Thanks for your prompt reply.


Top
 Profile  
 
 Post subject: Re: Locale based validation
PostPosted: Sat May 29, 2010 5:26 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Built-in support for a specific Locale is in the message interpolation. Other than that there is nothing out of the box. I also believe different validation.xml files per Locale would be not such a good idea.

If you want to go down this route, you could create multiple Validator instances - one per Locale. You can then choose the right validator for a specific Locale. This requires though that you are configuring the constraints via xml. Using the bootstrap configuration object you can pass arbitrary xml mapping files to the boostrapping process.

The Hibernate Validator 4.1 release will also contain a programmatic constraint configuration API (not part of the Bean Validation spec!) which will allow you to configure and create different Validator instances.

--Hardy


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