пятница, 11 апреля 2014 г.

Struts 2. Radio button example

JSP:
<s:radio list="myList" name="someProperty" listKey="key" listValue="value" />

Java action:
public String someProperty; // also getters and setters needed

public Set<Entry<String, String>> getMyList() {
 Map<String, String> map = new LinkedHashMap<String, String>();
 map.put("first", getText("message.from.properties.one"));
 map.put("second", getText("message.from.properties.two"));
 return map.entrySet();
}

Result:
<input type="radio" name="someProperty" id="myform_somePropertyfirst" value="first"/>
<label for="myform_somePropertyfirst">value of message.from.properties.one</label>
<input type="radio" name="someProperty" id="myform_somePropertysecond" value="second"/>
<label for="myform_somePropertysecond">value of message.from.properties.two</label>