Hello,
I'm doing a Web application using Spring 3.1.0.RELEASE, JSF 2.x, JPA 2 with Hibernate Provider. The application run on Tomcat 6.X.
The web-app can be show in different languages : en , es , fr.
I use the bean validation in my entities. Hibernate Validator is the provider, version 4.2.0.Final.
I have the following code in an entity:
Code:
@Email
@Size(max=255)
@Column(name = "email_ceo", length = 255)
private String emailCeo;
@NotEmpty
@OrderBy("position ASC")
@OneToMany(cascade = ALL, mappedBy = "site", fetch = FetchType.EAGER)
private List<SiteLanguage> langs;
I handle the exception like this:
Code:
try {
siteService.createSite(newSite);
} catch (ConstraintViolationException ex) {
final FacesContext facesContext = FacesContext.getCurrentInstance();
for (ConstraintViolation<?> cv : ex.getConstraintViolations()) {
facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, cv.getMessage(), null));
}
}
I display the error message in the template by using <h:messages />
How do I get the translated message, because cv.getMessage() always return the english message ?
For the email it works fine, i have the message in good language.
There is a second thing, I don't understand :
Why @NotEmpty throws a ConstraintViolationException and @Email doesn't ?
Thanks you.