无法弄清楚如何< s:select> [英] Can't figure it out how to <s:select>

查看:90
本文介绍了无法弄清楚如何< s:select>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图获得中的公司名单,选择但它给我一个错误。

 类型异常报告

消息标记'select',字段'list',名称'workOrder。公司':请求的列表键
'listAllCompanys'不能被解析为一个集合/数组/映射/枚举/迭代器
类型。示例:人员或人员{名称} - [未知位置]

描述
服务器遇到内部错误,无法完成此请求。

例外情况

  org.apache.jasper.JasperException:标记'select',字段'list',名称'workOrder.company':请求的列表键'listAllCompanys'无法解析为集合/数组/映射/枚举/迭代器类型。示例:人员或人员。{名称}  -  [未知位置] 
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:585)
org.apache.jasper.servlet.JspServletWrapper。服务(JspServletWrapper.java:470)

我的 workOrder.jsp 包含以下内容的文件:

 < s:select list =listAllCompanyslistValue =companyNamename =workOrder 。公司>< /秒:选择> 

当我有新的工作订单要添加时,应该有select中可用的公司列表。



更新:



以下是我的 listAllCompanies()方法

  public List< Company> getCompanyList(){
return companyList;
}

///////////////////////////////////// /////
/////////////////////////////////////////

公开清单<公司> getListAllCompanys(){
return listAllCompanys;
}

私人列表<公司> listAllCompanys;

public String listAllCompanys()抛出异常
{
CompanyDaoHibernate dao = new CompanyDaoHibernate();
listAllCompanys = dao.getListOfCompanys();

返回SUCCESS;




CompanyDAOHibernate

  public List< Company> getListOfCompanys()
{

SessionFactory sf = HibernateUtil.getSessionFactory();
会话会话= sf.openSession();

@SuppressWarnings(unchecked)
List< Company> returnList =(List< Company>)session.createCriteria(Company.class).list();
session.close();
System.out.println(Printing companies ...+ returnList);
返回returnList;



$解析方案

JSP包含操作返回的选择标记。当你添加一个订单时,它应该有一个绑定到bean属性的 list 属性。它应该是值堆栈中的顶部对象。

在大多数情况下,初始化action类中的属性可以更好地实现 可预备 您必须在其中编写 prepare()方法并初始化列表。

抛出异常是因为 s的列表属性:select 标记不能是 null 。您应该在返回引用该变量的结果之前正确初始化用于标记的变量。


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;

}

解决方案

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

这篇关于无法弄清楚如何&lt; s:select&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆