Domanda

In my message resources file i have following lines:

error.required={0} is required
labels.email=E-mail

To validate e-mail field I am using annotation validators, like this:

@RequiredStringValidator(key="error.required")
public String getEmail() {
    return email;
}

My question is: how can I pass the labels.email resource value to the {0} param to the message using RequiredStringValidator annotation? I was trying with messageParam property but without any success.

È stato utile?

Soluzione

Try this

@RequiredStringValidator(message = "${getText('error.required', new java.lang.String[] {getText('labels.email')})}")

The getText() could be used if your action extends ActionSupport to get the resource messages by the key specified as a parameter. It applied two times in the same expression to build your message. First time without parameter, second with the parameter and used overloaded getText() implementation.

Altri suggerimenti

How about like this?

@RequiredStringValidator(key="error.required", params={"1",getText("labels.email")})

or in Action-validation.xml

<field name="hove">
    <field-validator type="required">
        <message key="error.required">
            <param name="1">getText('labels.email')</param>
        </message>
    </field-validator>
</field>

Parameterized message might be rendered.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top