试图获取select
中的公司列表,但它给了我一个错误。
type Exception report
message tag 'select', field 'list', name 'workOrder.company': The requested list key
'listAllCompanys' could not be resolved as a collection/array/map/enumeration/iterator
type. Example: people or people.{name} - [unknown location]
description
The server encountered an internal error that prevented it from fulfilling this request.
例外:
org.apache.jasper.JasperException: tag 'select', field 'list', name 'workOrder.company': The requested list key 'listAllCompanys' 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:585)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
我的workOrder.jsp
文件包含:
<s:select list="listAllCompanys" listValue="companyName" name="workOrder.company"></s:select>
当我要添加新工单时,应该有一个公司列表可供选择。
更新:
这是我的listAllCompanies()
方法
public List<Company> getCompanyList() {
return companyList;
}
//////////////////////////////////////////
/////////////////////////////////////////
public List<Company> getListAllCompanys() {
return listAllCompanys;
}
private List<Company> listAllCompanys;
public String listAllCompanys() throws Exception
{
CompanyDaoHibernate dao = new CompanyDaoHibernate();
listAllCompanys = dao.getListOfCompanys();
return SUCCESS;
}
CompanyDAOHibernate
:
public List<Company> getListOfCompanys()
{
SessionFactory sf = HibernateUtil.getSessionFactory();
Session session = sf.openSession();
@SuppressWarnings("unchecked")
List<Company> returnList = (List<Company>)session.createCriteria(Company.class).list();
session.close();
System.out.println("Printing companies... "+returnList);
return returnList;
}
答案 0 :(得分:4)
JSP包含操作返回的select标记。添加订单时,它应该具有绑定到bean属性的list
属性。它应该是值堆栈中的top
对象。
在大多数情况下,最好在操作类中初始化该属性以实现Preparable
,您必须编写prepare()
方法并初始化列表。
抛出异常是因为list
标记的s:select
属性不能是null
。在返回引用该变量的结果之前,应正确初始化用于标记的变量。