Reputation: 1
I have a listbox in my input screen(Jsp in struts 2) and I want to display the selected items as a listbox in the output screen too. I tried using the preselect option but I am able to select only 1 value.
This is my input screen listbox code line:
<s:select multiple="true" name="color" label="Color" size="4" list="#{'1':'blue','2':'pink','3':'green','4':'purple','5':'crimson','6':'indigo'}" />
This is my output screen listbox code line:
<s:select multiple="true" name="colorN" label="ColorN" size="4" list="#{'1':'blue','2':'pink','3':'green','4':'purple','5':'crimson','6':'indigo'}" value="%{color}"/>
Upvotes: 0
Views: 4880
Reputation: 6811
Description of attribute s:select multiple :
Creates a multiple select. The tag will pre-select multiple values if the values are passed as an Array or a Collection(of appropriate types) via the value attribute. If one of the keys equals one of the values in the Collection or Array it wil be selected
Array : {4, 6}
<s:select
name="colorN"
multiple="true"
size="6"
list="#{1:'blue', 2:'pink', 3:'green', 4:'purple', 5:'crimson', 6:'indigo'}"
value="%{{4, 6}}"
/>
or
Collection : colors
public List<Integer> getColors() {
return Arrays.asList(4, 6);
}
_
<s:select
name="colorN"
multiple="true"
size="6"
list="#{1:'blue', 2:'pink', 3:'green', 4:'purple', 5:'crimson', 6:'indigo'}"
value="colors"
/>
Upvotes: 2