Hi I am wondering how to pass information to the exception handler. Say for example I doing validation. Whit @Valid. I can catch that specific exception but that does not tell me if was the first name or last name of the person that was wrong.
Maybe a custom exception with a error field attribute. If I do that is how to I through it? @Valid have already thrown an exception if validation fails.
Can i check the bindingresult for error and throw my custom exception? How do solve this?
@RequestMapping(value = "/post", method = RequestMethod.POST)
public String post(@Valid Person person) {
System.out.println(person);
System.out.println(person2);
return "home";
}
@ExceptionHandler(Exception.class)
@ResponseBody
public List<FailureResult> handleException
(Exception re, HttpServletResponse response) {
FailureResult failureResult = new FailureResult();
failureResult.setName("name");
//wich feild failed the validation?
List<FailureResult> r = new ArrayList<FailureResult>();
r.add(failureResult);
return r;
}