Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using @RequiredStringValidator messageParams in Struts 2

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.

like image 263
Kamil Chaber Avatar asked Jul 12 '26 19:07

Kamil Chaber


1 Answers

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.

like image 75
Roman C Avatar answered Jul 14 '26 18:07

Roman C