swetha
swetha

Reputation: 469

Sruts2 <s:radio /> with label read from .properties file

I am migrating the code from Struts1 to Struts2 where I have the following scenario:

<html:radio property="case" value="A" onclick="radioClickA();"/>
<bean:message key="label.A"/>

<html:radio property="case" value="B" onclick="radioClickB();"/>
<bean:message key="label.B"/> 

<html:radio property="case" value="C" onclick="radioClickC();"/>
<bean:message key="label.C"/>

Since in Struts2 we have to add all the above three radio buttons in one list, how can I add the localized label for each radio button ?

Upvotes: 1

Views: 1284

Answers (2)

swetha
swetha

Reputation: 469

I have wrote in different way and it worked.

<s:radio theme = "simple" 
          name = "case" 
          list = "#{'A':getText('label.A'), 'B':getText('label.B'), 'C':getText('label.C')}" 
       onclick = "radioClick();" 
/>

Upvotes: 1

Andrea Ligios
Andrea Ligios

Reputation: 50281

Assuming A,B,C to be Strings:

@Getter         private String[] cases = {"A","B","C"};
        @Setter private String case;
<s:radio name = "case" 
         list = "cases"
 listLabelKey = "%{'label.' + top}" 
      onclick = "radioClick(this.value);"
/>

Note that the top keyword was intended for internal use only,
and its usage might be inhibited in future versions of Struts.
Then you can use toString(), less elegant but rock-solid:

<s:radio name = "case" 
         list = "cases"
 listLabelKey = "%{'label.' + toString()}" 
      onclick = 'radioClick(this.value);'
/>

Upvotes: 3

Related Questions