Skip to content

Instantly share code, notes, and snippets.

@NatanCardoso
Created December 4, 2014 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NatanCardoso/343f10b371229178e089 to your computer and use it in GitHub Desktop.
Save NatanCardoso/343f10b371229178e089 to your computer and use it in GitHub Desktop.
Alterar caminho do ValidationMessages.properties no Hibernate Validator com VRaptor
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();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment