How can I translate Struts 2 validation messages?

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

I've created a file <MyActionClass>-validation.xml

and I'm wondering how can I translate the validation messages into 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 messages from the localized .properties file or do I need to use some other validation?

0


source to share


1 answer


Okay, I figured it out myself. You need to create a .properties file for the class, then you can change the code:

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

      



in

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

      

+1


source







All Articles