简体   繁体   English

无法弄清楚如何<s:select>

[英]Can't figure it out how to <s:select>

Trying to get list of companies in select but it gives me an error.试图获取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.

Exception:例外:

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)

my workOrder.jsp file containing :我的workOrder.jsp文件包含:

<s:select list="listAllCompanys"  listValue="companyName" name="workOrder.company"></s:select>

When I have a new work order to add, there should be a list of companies available in select .当我要添加新的工单时, select 中应该有可用的公司列表。

UPDATE:更新:

Here's my listAllCompanies() method这是我的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 : 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;

}

The JSP contains a select tag returned by the action. JSP 包含一个由操作返回的选择标记。 When you add an order it should have a list attribute bound to the bean property.添加订单时,它应该有一个绑定到 bean 属性的list属性。 It should be a top object in the value stack.它应该是值堆栈中的top对象。

In most cases initializing that property in the action class better to implement the preparable interface where you have to write prepare() method and initialize the list.在大多数情况下,在操作类中初始化该属性更好地实现可prepare() the preparable interface ,您必须在其中编写prepare()方法并初始化列表。

The exception is thrown because the list attribute of the s:select tag couldn't be null .抛出异常是因为s:select标记的list属性不能为null You should properly initialize the variable used for the tag before returning a result that has references to that variable.在返回引用该变量的结果之前,您应该正确初始化用于标记的变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM