I18n in validation messages

57 views
Skip to first unread message

Miguel Orbegozo

unread,
Sep 6, 2014, 5:40:28 AM9/6/14
to caelum-v...@googlegroups.com
Hi again!

I have a question about the i18n of the validation messages (default and custom).

I have the ValidationMessages.properties whit two languagues, but the validator doesnt use the same Locale that the JSTL (wouldn't it?).

In another controller I have i18n the messages to the browser with:

result.include("message", jstlLocalization.getBundle().getObject("user.login.error"));



Is it a bug in the validator or am i missing anything (again)?

Thanks:

Miguel

Rodrigo Turini

unread,
Sep 6, 2014, 2:54:22 PM9/6/14
to caelum-v...@googlegroups.com
Hi Miguel! An way to do that would be injecting ResourceBundle 
(VRaptor will provide a safe implementation that doesn't throw a
exception for missed keys) and using its getString method, just like:

@Inject private ResourceBundle bundle
...
result.include("message", bundle.getString("user.login.error"));

It should work as you're expecting... but if it is a validation msg,
maybe you'd like to use our Validation API, you can see some docs

boolean loginError = // ...
validator.addIf(loginsError, new I18nMessage("user.login.error"));
validator.onErrorUsePageOf(this).loginForm();

The I18nMessage will load the message from ResourceBundle. []'s

Rodrigo Turini
Caelum | Ensino e Inovação
www.caelum.com.br



--
You received this message because you are subscribed to the Google Groups "caelum-vraptor-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to caelum-vraptor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Miguel Orbegozo

unread,
Sep 6, 2014, 3:26:50 PM9/6/14
to caelum-v...@googlegroups.com
Thanks Rodrigo for your support.

My problem is the bean validation messages. With your aproach I need to write the code that validates and now I'm trying the annotations. I have:

I have a user class annotated with:

    @NotNull @Size(min=8, max=20)
    private String name;
   
    @NotNull @Size(min=6)
    private String pass;

    @NotNull @Pattern(regexp="^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$", message="{user.mail.invalid}")
    private String mail;

The validations works fine, but the messages aren't internacionalized with Jstl Locale (in the same page the jstl messages are in one language and the validation ones in other language). Isn't the Jstl Locale being passed to the message interpolator?

Thanks again for your support anf for your work in VRaptor.

Miguel

Rodrigo Turini

unread,
Sep 7, 2014, 2:23:01 PM9/7/14
to caelum-v...@googlegroups.com
Hi Miguel! Now I see your point, it really sounds like a bug. Please, can 
you open an issue here? We'll work on it as fast as possible. If you know
a simple way to fix it, please feel free sending us a pull request. Thanks

Rodrigo Turini
Caelum | Ensino e Inovação
www.caelum.com.br



--

Miguel Orbegozo

unread,
Sep 8, 2014, 2:27:41 PM9/8/14
to caelum-v...@googlegroups.com, rodrigo...@caelum.com.br
I have opened the issue:

https://github.com/caelum/vraptor4/issues/788

Thanks:

Miguel

Rodrigo Turini

unread,
Sep 17, 2014, 2:15:54 PM9/17/14
to caelum-v...@googlegroups.com
Hi Miguel! The VRaptor 4.1.0-RC3 was launched with this bug fixed. 
Its available on maven/bintray. Thanks again for reporting the issue.

Rodrigo Turini
Caelum | Ensino e Inovação
www.caelum.com.br


Reply all
Reply to author
Forward
0 new messages