1

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 ?

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
swetha
  • 449
  • 7
  • 20
  • *Since in Struts2 we have to add all the above three radio buttons in one list* - You **can**, doesn't mean you **have to**. – Aleksandr M Nov 19 '15 at 10:07

2 Answers2

2

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);'
/>
Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
1

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();" 
/>
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
swetha
  • 449
  • 7
  • 20
  • Yes, this is another way, for small lists I use it too (but usually in only) – Andrea Ligios Nov 19 '15 at 13:43
  • @swetha I tried your solution but I this error occured: `org.apache.jasper.JasperException: Error on line 31, column 9 in template/simple/radiomap.ftl stack.findString(parameters.listValue) is undefined. It cannot be assigned to itemValue - Class: freemarker.core.Assignment` – Ariana Mar 10 '17 at 13:39