Reputation: 129
JSP:
<s:form action="product">
<s:select label="Select Data"
cssStyle="width:150; height:73"
size="6"
multiple="true"
headerKey="-1" headerValue="All"
list="#{'1':'Data1', '2':'Data2', '3':'Data3', '4':'Data4' }"
name="dataValue"
value="%{2,3}" />
<s:submit value="save"></s:submit>
</s:form>
Action:
public class Product {
private String dataValue;
//getter setter
.......
public String execute(){
return "success";
}
}
Problem:
Simultaneously, only one field is selected. For example, I passed the value 2,3
, but only Data3
is selected. I need Data2
and Data3
both to be selected.
Upvotes: 0
Views: 1472
Reputation: 1
To pre-select multiple values you need to use list or array for the action property in the value
attribute.
'1', '2',... are character type values, so you return a character list
public List<Character> getDataValue(){
return dataValue;
}
<s:select label="Select Data"
cssStyle="width:150; height:73"
size="6"
multiple="true"
headerKey="-1" headerValue="All"
list="#{'1':'Data1', '2':'Data2', '3':'Data3', '4':'Data4' }"
name="dataValue"
value="%{dataValue}" />
Upvotes: 1