Friday, March 4, 2011

How can I translate the validation messages of Struts 2?

I want to learn how to use Struts 2 and I created a simple application following a tutorial I found.

I've created a <MyActionClass>-validation.xml file and I wonder how can I translate the validation messages to multiple languages?

<field name="password">
    <field-validator type="requiredstring">
  <param name="trim">true</param>
  <message>You have to enter a password.</message> 
                 <!-- How can I localize this message? -->
 </field-validator>
</field>

Can I get the messages from a localized .properties file or do I have to use some other kind of validation?

From stackoverflow
  • OK, I found it out myself. You have to create a .properties file for the class, then you can change the code from:

    <message>You have to enter a password.</message>
    

    to:

    <message key="[message key from the properties file]" />
    

0 comments:

Post a Comment