[hibernate-issues] [Hibernate-JIRA] Commented: (ANN-458) Hibernate Validator initialization always requires keys in ValidatorMessges.properties

Emmanuel Bernard (JIRA) noreply at atlassian.com
Mon Oct 16 15:13:24 EDT 2006


    [ http://opensource.atlassian.com/projects/hibernate/browse/ANN-458?page=comments#action_24821 ] 

Emmanuel Bernard commented on ANN-458:
--------------------------------------

I mean the fix/hack is broken, you should set string to token and also take the delimiters into account.


This problem should certainly not be blocker. You must set up all your keys anyway to have a fully functional application. An application where 
"{message.wrong_size} 34"
pops up to the user always looks like a toy app to me.

> Hibernate Validator initialization always requires keys in ValidatorMessges.properties
> --------------------------------------------------------------------------------------
>
>          Key: ANN-458
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-458
>      Project: Hibernate Annotations
>         Type: Bug

>   Components: binder
>     Versions: 3.2.0.ga
>     Reporter: Christian Bauer
>     Priority: Blocker
>      Fix For: 3.2.1

>
>
> Seam + Hibernate Validator doesn't work. When AnnotationConfiguration boots, it always uses the DefaultMessageInterpolator (this is actually a separate problem, not only the event listeners should use the configured interpolator) and the default interpolator always throws an exception if the message key can't be found.
> This is an even bigger problem if you don't want or have a ValidatorMessages.properties file, like in a typical Seam application where everything is in messages.properties (Seam managed component). You can't override or set the resource bundle that is used on startup.
> A quick fix would be to not throw an exception in DefaultMessageInterpolator if the key can't be found in the resource bundle. The key should then be returned as the message. I see no reason why that shouldn't work, it's the users own fault if he forgot the key. It's also the regular behavior in JSF.
> This is my quick hack to make it work, in DefaultMessageInterpolator:
> 					String string = null;
> 					try {
> 						string = messageBundle != null ? messageBundle.getString( token ) : null;
> 					}
> 					catch( MissingResourceException e ) {
> 						//give a second chance with the default resource bundle
> 					}
> 					if (string == null) {
> 						try {
> 							string = defaultMessageBundle.getString( token );
> 						}
> 						catch( MissingResourceException e) {
>                             return message;
>                             /* We don't want that:
>                             throw new MissingResourceException(
> 									"Can't find resource in validator bundles, key " + token,
> 									defaultMessageBundle.getClass().getName(),
> 									token
> 							);
> 							*/
> 						}
> 					}
> I'm writing now about this in the JPwH book, so I expect that I can in the future simply have messages.properties for Seam with my Hibernate Validator messages. This fix has to be in 3.2.1.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list