-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Beans validation mutli lang message fail
PostPosted: Thu Apr 05, 2012 1:43 pm 
Newbie

Joined: Thu Apr 05, 2012 1:40 pm
Posts: 2
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.