Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
378 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...