javavalidationpropertiesstruts2internationalization

How to display the validation messages based on multiple languages in Struts 2?


I am using 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 display the validation messages based on multiple languages?

<field name="password">
    <field-validator type="requiredstring">
        <param name="trim">true</param>
        <message>You have to enter a password.</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?

Should there be validation XML files for every locale?


Solution

  • Just use <message key="key_name"/> inside your ActionClass-validation.xml

    Then you define key_name in

    global.properties
    global_vn.properties
    

    Make sure you have request_locale in your stack.