Created
December 4, 2014 20:10
-
-
Save NatanCardoso/343f10b371229178e089 to your computer and use it in GitHub Desktop.
Alterar caminho do ValidationMessages.properties no Hibernate Validator com VRaptor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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