Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: JSR303 1.1: resource bundles in constraint annot. package
PostPosted: Mon Apr 04, 2011 10:52 am 
Newbie

Joined: Mon Apr 04, 2011 10:24 am
Posts: 3
This is a proposal for the new version of JSR 303 (v1.1 ?).

The proposal is: modify the default message interpolation algorithm (section 4.3.1.1) so that the validation engine looks for a Resource Bundle called "ValidationMessages" in the constraint annotation's own package.

For example, when validating constraint annotation com.gdpcons.constraints.MustEqual, validator should also look for messages in a resource bundle called com.gdpcons.constraints.ValidationMessages.

The constraint annotation package ValidationMessages resource bundle should be checked after the "user" ValidationMessages resource bundle, but before the BeanValidation provider's own private ValidationMessages resource bundle, so as to allow users to override the string provided by the constraint annotation resource bundle.

This would allow people to write redistributable collections of constraint annotations, since as of today it's not possible to use multiple ValidationMessages resource bundles files (one will override all the others in the classpath); and it would still allow users to override the provided translation just by a new definition for the message key in their own ValidationMessages resource bundle.

I've written an example implementation, by modifying Hibernate Validator's own ResourceBundleMessageInterpolator. It seams to work without side effects, and is a very straightforward implementation.

Should I open an enhancement on the JSR 303 issue tracker? Is my proposal interesting?


Top
 Profile  
 
 Post subject: Re: JSR303 1.1: resource bundles in constraint annot. package
PostPosted: Sun Apr 24, 2011 12:33 pm 
Newbie

Joined: Wed Apr 20, 2011 8:45 pm
Posts: 6
You might be interested in my mod of MessageInterpolator. It allows to specify RB name by the property name: viewtopic.php?f=26&t=1010669


Top
 Profile  
 
 Post subject: Re: JSR303 1.1: resource bundles in constraint annot. package
PostPosted: Sun May 01, 2011 4:46 pm 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 176
Hi,

you are right, there's definitely space for improvement in this area. I saw you already opened BVAL-225 for this; that's great to track this.

Just one note, you might find Hibernate Validator's AggregateResourceBundleLocator useful. This allows to merge several resource bundles into one. So if you have the constraint modules under your control, you could put a uniquely named resource bundle into each module and create an aggregated bundle locator for all these bundles. That way each constraint module would come with its own resource bundle while the texts still can be overridden with the ones from ValidationMessages.

-- Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: JSR303 1.1: resource bundles in constraint annot. package
PostPosted: Wed May 18, 2011 3:39 am 
Newbie

Joined: Mon Apr 04, 2011 10:24 am
Posts: 3
Hi Gunnar,

I've seen AggregateResourceBundleLocator and considered using it, but in the end we simply use one single ValidationMessages resource bundle with all the strings, also because our app is in Italian and HV's version I'm using (4.0.2) lacks an italian translation for the standard constraints.

The approach I propose is more plug-and-play.

On a side note, if you need an italian translation for the standard constraints , I can provide it.

--
Regards,
Gabriele


Top
 Profile  
 
 Post subject: Re: JSR303 1.1: resource bundles in constraint annot. package
PostPosted: Wed May 18, 2011 5:17 pm 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 176
Hi Gabriele,

good to hear that you found a solution which works for you. Having an Italian resource bundle would be great and your help is highly appreciated. Could you open a JIRA issue for HV and attach the resource bundle to it?

Thanks,

Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: JSR303 1.1: resource bundles in constraint annot. package
PostPosted: Tue Aug 23, 2011 12:45 pm 
Newbie

Joined: Tue Aug 23, 2011 12:33 pm
Posts: 1
Quote:
On a side note, if you need an italian translation for the standard constraints , I can provide it.

can you share it?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 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.