2014-11-03 95 views
0

我有一个需要使用Struts 2选择标记填充的下拉列表。我得到下面的例外。错误在哪里?struts 2选择标记异常

<s:select label="Country" headerKey="-1" headerValue="Select Country" list="countries" 
               listKey="key" listValue="label" name="searchForm.custCountry"/> 

在我的动作类中,我有以下声明,后面跟着getters和setters。

ArrayList<DropDown> countries = new ArrayList<DropDown>(); 


    SEVERE: Servlet.service() for servlet jsp threw exception 
    tag 'select', field 'list', name 'searchForm.custCountry': The requested list key 'countries' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location] 
     at org.apache.struts2.components.Component.fieldError(Component.java:240) 
     at org.apache.struts2.components.Component.findValue(Component.java:333) 
     at org.apache.struts2.components.ListUIBean.evaluateExtraParams(ListUIBean.java:80) 
     at org.apache.struts2.components.Select.evaluateExtraParams(Select.java:105) 
     at org.apache.struts2.components.UIBean.evaluateParams(UIBean.java:902) 
     at org.apache.struts2.components.UIBean.end(UIBean.java:544) 
     at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42) 
     at org.apache.jsp.accountSearchDtls_jsp._jspx_meth_s_005fselect_005f0(accountSearchDtls_jsp.java:979) 
     at org.apache.jsp.accountSearchDtls_jsp._jspx_meth_s_005fdiv_005f0(accountSearchDtls_jsp.java:935) 
     at org.apache.jsp.accountSearchDtls_jsp._jspService(accountSearchDtls_jsp.java:521) 
     at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:723) 
     at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388) 
     at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) 
     at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) 
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:723) 
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
     at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:96) 
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) 
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) 
     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) 
     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 
     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) 
     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 
     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) 
     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861) 
     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606) 
     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) 
     at java.lang.Thread.run(Thread.java:745) 

这里是我得到下拉列表的数据的方式。我已经足够了,如果不让我知道的话。

public ArrayList<DropDown> getCountrydd() { 
     ArrayList<DropDown> countrydd = new ArrayList<DropDown>(); 
     try { 
      OraConn conn = new OraConn(); 
      conn.getConnection(); 
      cstmt = conn.setProc("call mgm.getCountry(?)"); 
       cstmt.registerOutParameter(1, OracleTypes.CURSOR); 
       cstmt.execute(); 
     rs = (OracleResultSet)cstmt.getObject(1); 
       countrydd = rsToDropDown(rs); 

     } catch (Exception e) { 
       e.printStackTrace(); 
       //log.error("***getDSdropdowns*** "); 
     } finally { 
      closeORAConnection(); 
     } 
     return countrydd; 
    } 
+0

显示的代码中你是如何填充列表。 – 2014-11-03 19:53:57

回答

1

您需要更改代码来填充列表

public ArrayList<DropDown> getCountrydd() { 

    List<DropDown> countrydd = new ArrayList<DropDown>(); 
    OraConn oraConn = new OraConn(); 
    Connection conn = null; 
    CallableStatement cstmt = null; 
    ResultSet rs = null; 
    try { 
     conn = oraConn.getConnection(); 
     cstmt = conn.prepareCall("{call mgm.getCountry(?)}"); 
     cstmt.registerOutParameter(1, OracleTypes.CURSOR); 
     cstmt.executeUpdate(); 
     rs = (ResultSet)cstmt.getObject(1); 

     rsToDropDown(rs, countrydd); 

    } catch (Exception e) { 
      e.printStackTrace(); 
      //log.error("***getDSdropdowns*** "); 
    } finally { 
     if (rs != null) 
      rs.close();    
     if (cstmt!= null) 
      cstmt.close();    
     if (conn != null) 
      conn.close();     
    } 
    return countrydd; 
} 
+0

你试图指出的变化是什么@罗曼C – 2014-11-03 21:48:19

+0

这是调用一个存储过程,返回一个带有结果的列表。我写这个是因为你的代码有很多bug。 – 2014-11-04 08:26:35

0

我发现我是填充我的组合框或与国家价值观下拉列表即使用户是零,因为这个原因,当我点击创建新用户按钮我得到这些例外。现在我改变了我的代码,这是它现在是什么:

public String getProfile() throws Exception { 

    user_name =(String) sessionMap.get("userid") ; 

    MgmService service = new MgmService(); 
    userForm = new User(); 
    userForm = service.getUsersProfile(user_name); 

    if(searched_user_name!=null){ 
     userForm = service.getUsersProfile(searched_user_name); 
     countries= service.getCountrydd(); //This keep the content of the combobox by default on the list 
     return "createEditUser"; 
    } 
    else if(userForm!=null) 
    { 
     return "success"; 
    } 

    else { 
     addActionError("Invalid Login."); 
     return "success"; 
    } 
} 

这是我的错代码之前.....

public String getProfile() throws Exception { 

    user_name =(String) sessionMap.get("userid") ; 

    MgmService service = new MgmService(); 
    userForm = new User(); 

    userForm = service.getUsersProfile(user_name); 
    countries= service.getCountrydd(); //This keep the content of the combobox by default on the list 
    if(searched_user_name!=null){ 
     userForm = service.getUsersProfile(searched_user_name); 
     return "createEditUser"; 
    } 
    else if(userForm!=null) 
    { 
     return "success"; 
    } 

    else { 
     addActionError("Invalid Login."); 
     return "success"; 
    } 
}