-->
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.  [ 5 posts ] 
Author Message
 Post subject: How can I supply a custom Resource Bundle to JPA/JSF
PostPosted: Tue Mar 15, 2011 11:55 am 
Newbie

Joined: Fri Mar 12, 2010 9:42 am
Posts: 19
Hi everybody
I have managed to use a custom resource bundle when doing explicit validation like explained here:
http://musingsofaprogrammingaddict.blog ... chive.html

I.e. if I do this:

Code:
      ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class).configure().messageInterpolator(new ResourceBundleMessageInterpolator(myCustomResourceBundleLocator)).buildValidatorFactory();
      Validator validator = validatorFactory.getValidator();
      constraintViolations = validator.validate(myObj, Default.class);


It works as expected. But, we're not doing explicit validation, this is being performed by both our JSF framework (mojarra) in the frontend, and JPA in the backend (Hibernate). How can I configure these to use our custom resource bundle?

And another thing.. Where does the locale that is passed as a parameter to my resource bundle come from?

All help would be greatly appreciated!

Regards, Anders


Top
 Profile  
 
 Post subject: Re: How can I supply a custom Resource Bundle to JPA/JSF
PostPosted: Tue Mar 15, 2011 3:23 pm 
Contributor
Contributor

Joined: Mon Feb 28, 2011 7:27 pm
Posts: 20
Location: France
Hi,

Quote:
Code:
ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class).configure().messageInterpolator(new ResourceBundleMessageInterpolator(myCustomResourceBundleLocator)).buildValidatorFactory();
Validator validator = validatorFactory.getValidator();
constraintViolations = validator.validate(myObj, Default.class);

It works as expected. But, we're not doing explicit validation, this is being performed by both our JSF framework (mojarra) in the frontend, and JPA in the backend (Hibernate). How can I configure these to use our custom resource bundle?


The ValidatorFactory can be configured in two ways, by using the programmatic approach like the above code or with an xml configuration file as it's explained in the reference guide http://docs.jboss.org/hibernate/validator/4.2/reference/en-US/html_single/#d0e1993. I think adding the configuration file (which configure your custom ResourceBundleLocator) in the classpath will work.

Quote:
And another thing.. Where does the locale that is passed as a parameter to my resource bundle come from?


With JSF2 and Bean Validation integration it's the client locale (chapter 3.5.6.3 of the JSF2 specification) otherwise I think it's the server locale.

Hope this help
--
Kevin


Top
 Profile  
 
 Post subject: Re: How can I supply a custom Resource Bundle to JPA/JSF
PostPosted: Wed Mar 16, 2011 6:54 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Welcome on the forum Kevin :-)


Top
 Profile  
 
 Post subject: Re: How can I supply a custom Resource Bundle to JPA/JSF
PostPosted: Wed Mar 16, 2011 7:06 am 
Newbie

Joined: Fri Mar 12, 2010 9:42 am
Posts: 19
Thanks for helping Kevin!

I managed to get it working. It looks like it's not possible to set the ResourceBundleLocator in validation.xml, but it is possible to set a MessageInterpolator which in turn can use your own ResourceBundleLocator. As explained by Hardy here:
viewtopic.php?f=9&t=1004915&start=15

Seems to be working like a charm! Only problem I got is that the MessageInterpolator is not managed, so I had to look up my beans using the BeanManager.

Regards,

Anders


Top
 Profile  
 
 Post subject: Re: How can I supply a custom Resource Bundle to JPA/JSF
PostPosted: Wed Mar 16, 2011 8:41 am 
Contributor
Contributor

Joined: Mon Feb 28, 2011 7:27 pm
Posts: 20
Location: France
That was my idea but misspoken :)

--
Kevin


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