Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
365 views
in Technique[技术] by (71.8m points)

java - Can't figure it out how to <s:select>

Trying to get list of companies in select but it gives me an error.

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 :

<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 .

UPDATE:

Here's my listAllCompanies() method

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;

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The JSP contains a select tag returned by the action. When you add an order it should have a list attribute bound to the bean property. It should be a top object in the value stack.

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.

The exception is thrown because the list attribute of the s:select tag couldn't be null. You should properly initialize the variable used for the tag before returning a result that has references to that variable.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...