Skip to content

Instantly share code, notes, and snippets.

@marceloemanoel
Created August 18, 2011 20:17
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 marceloemanoel/1155073 to your computer and use it in GitHub Desktop.
Save marceloemanoel/1155073 to your computer and use it in GitHub Desktop.
Problema de validação do Vraptor
@Get
@Path("/")
public void consultar(final Requisicao requisicao) {
validator.checking(new Validations() {{
that(requisicao, Matchers.notNullValue(), "requisicao", "parametro.obrigatorio", "requisicao");
}});
if(validator.hasErrors()){
System.out.println("encontrou um erro");
}
validator.onErrorUse(Results.xml()).from(validations.getErrors()).serialize(); //mostra um xml com as chaves do i18n do erro
validator.onErrorUse(Results.status()).badRequest("Mensagem de erro"); //funciona -> retorna um erro 400 - Mensagem de erro
validator.onErrorUse(Results.status()).badRequest(validations.getErrors()); // não funciona -> continua como se não houvesse problemas
validator.onErrorSendBadRequest(); //não funciona -> continua como se não houvesse problemas
....
}
@wbotelhos
Copy link

@marceloemanoel
Copy link
Author

marceloemanoel commented Aug 18, 2011 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment