quinta-feira, 4 de dezembro de 2014

Alterar caminho do ValidationMessages.properties no Hibernate Validator com VRaptor

Inclua a classe abaixo dentro do projeto:

Basta alterar a variável "MESSAGES", foi testado no VRaptor 3.5.3

https://gist.github.com/NatanCardoso/343f10b371229178e089 

Referências:
http://beanvalidation.org/1.0/spec/#table-messageinterpolation


import javax.annotation.PostConstruct;
import javax.validation.MessageInterpolator;
import javax.validation.Validation;
import javax.validation.ValidatorFactory;
 
import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator;
import org.hibernate.validator.resourceloading.PlatformResourceBundleLocator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
import br.com.caelum.vraptor.ioc.ApplicationScoped;
import br.com.caelum.vraptor.ioc.Component;
import br.com.caelum.vraptor.validator.MessageInterpolatorFactory;
 
@ApplicationScoped
@Component
public class MessageInterpolatorFactoryHelper extends MessageInterpolatorFactory{
 
private static final String MESSAGES = "messages";
 
private static final Logger LOG = LoggerFactory.getLogger(MessageInterpolatorFactory.class);
 
private MessageInterpolator interpolator;
 
@Override
@PostConstruct
public void createInterpolator() {
interpolator = getValidatorFactory().getMessageInterpolator();
LOG.debug("Initializing Bean Validator MessageInterpolator Helper");
}
 
public MessageInterpolator getInstance() {
return interpolator;
}
private ValidatorFactory getValidatorFactory() {
return Validation.byDefaultProvider()
.configure()
.messageInterpolator(new ResourceBundleMessageInterpolator(new PlatformResourceBundleLocator(MESSAGES)))
.buildValidatorFactory();
}
} 
 
 

Nenhum comentário:

Postar um comentário