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 ?
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);'
/>