I'm trying to capture a javax.validation.ValidationException
in my MB to play on an alert later. I tried with the three examples below independent but nothing returned. Should I enter any more code? I use version 2.5.0.
@ViewController
public class MeuMB extends AbstractEditPageBean<CTe, Long> {
@ExceptionHandler
public void tratar(RuntimeException ex) {
System.out.println("1111" + ex);
}
@ExceptionHandler
public void tratar2(ValidationException ex) {
System.out.println("2222" + ex);
}
@ExceptionHandler
public void tratar3(Exception ex) {
System.out.println("3333" + ex);
}
The class has @ViewController and in it already calls the @Controller.
My calling method is as follows:
public String upload() {
//int i = 5 / 0;
try {
this.gera();
} catch (Exception ex) {
getMessageContext().add(getResourceBundle().getString("cte.msg.uploadFail"), SeverityType.ERROR);
return null;
}
If I take the comment "5/0," an error occurs and is called the RuntimeException. So calls and imports would be ok.
Problem is that in the "generate" method I force null in a not null field. Just to test.
@NotNull
@JoinColumn(name = "municipio_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private Municipio municipio;
And this error I am not able to capture neither in the try catch nor by the calls ExceptionHandler.