tags:

views:

56

answers:

2

Hi,

How to achieve parameterized message in struts2. in actioname-validation.xml i have

<field name="family.familyName">
        <field-validator type="requiredstring">
            <param name="trim">true</param>
            <message key="common.required">
                <argo key="common.family" />
            </message>
        </field-validator>
    </field>

resource file i have,

common.required = {0} is required.
common.family = Family

some thing like this i tried. how to achive this?

A: 

This article explains how to do what you want. The gist of it is that you'd define your validation rule as follows:

<field name="family.familyName">
    <field-validator type="requiredstring">
        <param name="trim">true</param>
        <message key="common.required"/>
    </field-validator>
</field>

And then in your .properties file, you'd have the following:

common.required = ${getText(fieldName)} is required.
family.familyName = Family
Pat
Hi,Thanks for your reply. family.familyName i can't use. because in some other places i have to use something like, product.family.familyName, that time i have to define one more attribute.
Jothi
A: 

It gives me, what i expected

<field name="family.familyName">
        <field-validator type="requiredstring">
            <param name="trim">true</param>
            <message>
                ${getText("requiredstring", {getText("common.family")})}
            </message>
        </field-validator>
    </field>

Application Resources,

requiredstring = {0} is required.
common.family = Family
Jothi