0

我想填充 arrayList 类型的 catList 对象以选择带有 key=catId 和 value=catName 的框

public class GamesAction extends ActionSupport {
 private ArrayList catList;

 public String populate() {
    GamesCategoryBusiness gcb = new GamesCategoryBusiness();
    Map data = gcb.fetchAll();//fetching games category from database
    String status = (String) data.get("status");
    if (status.equalsIgnoreCase("success")) {
        setCatList((ArrayList) data.get("gameCatList"));
        return "POPULATE";
    } else {
        addActionError("Not able to fetch Game categories");
        return INPUT;
    }



 public ArrayList getCatList() {
    return catList;
}

public void setCatList(ArrayList catList) {
    this.catList = catList;
}

}

另一个班级

 public class GamesCategoryAction extends ActionSupport {

private long catId;
private String catName;

public long getCatId() {
    return catId;
}

public void setCatId(long catId) {
    this.catId = catId;
}

public String getCatName() {
    return catName;
}

public void setCatName(String catName) {
    this.catName = catName;
}

在 struts.xml 中

 <action name="gameCatAdded" class="GamesCategoryAction"
            method="addCategory">
        <result name="POPULATE">/allCategory.jsp</result>
        <result name="success">/allCategory.jsp</result>
        <result name="input">/addCategory.jsp</result>
        <result name="login">/login.jsp</result>
    </action>

在 Jsp 中

 <s:select list="catList"
                     listKey="catId"
                     listValue="catName"
                     name="gamesCategoryId"
                     label="Category"
                     labelposition="top"/>

在jsp页面中显示以下错误异常

org.apache.jasper.JasperException: tag 'select', field 'list', name 'gamesCategoryId':    The requested list key 'catList' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
       org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:584)
4

1 回答 1

0

试试这个:ArrayList<Catalog> catList在动作课上。如果您从未声明过您的对象类型,那么您的对象类型是未知的。(假设您有一个名为 的域类Catalog,其中包含catIdcatName

于 2012-09-21T20:39:08.353 回答