Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: ResourceBundle different from the JVM
PostPosted: Thu Mar 04, 2010 12:31 pm 
Newbie

Joined: Thu Mar 04, 2010 12:09 pm
Posts: 1
Hi,
I'm new in the world hibernate validator
I'm implementing a method of type
org.springframework.validation.Validator I should take the Locale of the JVM but no file properties.

Even utilizando Local local = LocaleContextHolder.getLocale ();
ResourceBundle method returns the default locale of the JVM and then subsequently also MessageInterpolator wrong

the code I use is:

public class InsertUtenteValidator implements org.springframework.validation.Validator, InitializingBean {
private static final Log logger = LogFactory.getLog(InsertUtenteValidator.class.getName());
private Validator validator;


public void afterPropertiesSet() throws Exception {



}

public boolean supports(Class clazz) {
return UtenteCommand.class.isAssignableFrom(clazz);
}

public void validate(Object object, Errors errors) {

Locale locale = LocaleContextHolder.getLocale();
logger.info("Llocale: '" + locale );
ResourceBundle bundle = ResourceBundle.getBundle("org/hibernate/validator/ValidationMessages", locale);
MessageInterpolator interpolator = new ResourceBundleMessageInterpolator(bundle);
ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
validator = validatorFactory.usingContext().messageInterpolator(interpolator).getValidator();

UtenteCommand command = (UtenteCommand) object;
Utente ute = command.getUtente();
Set<ConstraintViolation<Utente>> violations = validator.validate(ute);
for (ConstraintViolation<Utente> constraintViolation : violations) {
String propertyPath = constraintViolation.getPropertyPath().toString();
logger.info("propertyPath: '" + propertyPath );
String message = constraintViolation.getMessage();
logger.info("message: '" + message );
errors.rejectValue("utente."+propertyPath,null, message);

}
}
}


Top
 Profile  
 
 Post subject: Re: ResourceBundle different from the JVM
PostPosted: Sat Aug 14, 2010 2:50 am 
Newbie

Joined: Sat Aug 14, 2010 12:45 am
Posts: 3
As I know one thing and if I noticed right away was the fact that we were most likely creating multiple entries in both maps that ended up containing identical copies of a same skin or resource bundle content.If the exact match resource bundle does not exist, the method attempts to find a resource bundle for the default JVM locale.And above information include vast information related this.

_________________
Life is either a daring adventure or nothing.


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