The attribute is listused to get the iterative source, while the attribute is nameused to set the selected item. Also use a tag <s:select/>for cleaner (and much simpler) code. For example:
Struts.xml
<action name="firstAction" class="foo.bar.FirstAction">
<result>firstPage.jsp</result>
</action>
<action name="secondAction" class="foo.bar.SecondAction">
<result>secondPage.jsp</result>
</action>
FirstAction.java
private List<String> userList;
public String execute(){
userList = getMyService().findUserList();
return SUCCESS;
}
FirstPage.jsp
<s:form action="secondAction" >
<div class="select_wrap">
<s:select list = "userList"
name = "selectedItem"
cssClass = "select_field"
multiple = "multiple" />
</div>
<s:submit value="Post your selection to second Action" />
</s:form>
SecondAction.java
private String selectedItem;
public String execute(){
log.debug("Selected item is: " + selectedItem);
return SUCCESS;
}
SecondPage.jsp
<div>
Selected item is: <s:property value="selectedItem" />
</div>
source
share