1

我对 Struts2 很陌生,受到多选标签的影响。我已经搜索了很多地方,但未能得到解决方案。这是我的问题:

在 JSP 中,我使用了这样的 struts2 选择标签

<s:form action="AjaxSaveSelectedStatus">
   <s:select label="Select Status" name="masterStatusLists" id="masterStatusLists" 
      list="#{'1':'status1','2':'status2','3':'status3','4':'status4'}" 
      multiple="true" required="true"/>
   <input type="submit" value="Save"/>
</s:form>

在struts.xml 映射

<action name="Ajax*" class="com.mypackage.actions.forms.Ajax{1}">
        <result name="redirect">${redirectUrl}</result>
    </action>

在 Action 课上我用过这样

public class AjaxSaveSelectedStatus extends BaseAjaxActionWithSession {
ArrayList<MasterStatusList> masterStatusLists;

@Override
public String execute(){

    for (MasterStatusList masterStatusList : masterStatusLists) {
        System.out.println(masterStatusList.getStatusId());
    }
    return SUCCESS;
}
public ArrayList<MasterStatusList> getMasterStatusLists() {
    return masterStatusLists;
}

public void setMasterStatusLists(ArrayList<MasterStatusList> masterStatusLists) {
    this.masterStatusLists = masterStatusLists;
}
}

这是 MasterStatusList Bean 类

public class MasterStatusList implements java.io.Serializable {
   private int statusId;
   private String statusName;
   public MasterStatusList() {}
   public int getStatusId() {return this.statusId;}
   public void setStatusId(int statusId) {this.statusId = statusId;}
   public String getStatusName() {return this.statusName;}
   public void setStatusName(String statusName) {this.statusName = statusName;}
}

现在我想在客户端获取所选项目的列表以执行操作。

4

1 回答 1

3

The value submitted by a multi select tag will be a List(or array or string of csv) of string(in your case integer 1,2,3..). So declare the List of Integers in you action class

List<Integer> masterStatusLists; //and its getter/setter

This must solve the issue

于 2012-10-25T05:27:57.037 回答