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

2023-09-24Java开发问题
1

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

问题描述

试图在 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.

例外:

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>

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

When I have a new work order to add, there should be a list of companies available in 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;

}

推荐答案

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

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.

在大多数情况下,在操作类中初始化该属性以更好地实现 准备接口你必须在其中编写prepare()方法并初始化列表.

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.

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

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;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

如何使用 JAVA 向 COM PORT 发送数据?
How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)...
2024-08-25 Java开发问题
21

如何使报表页面方向更改为“rtl"?
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)...
2024-08-25 Java开发问题
19

在 Eclipse 项目中使用西里尔文 .properties 文件
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)...
2024-08-25 Java开发问题
18

有没有办法在 Java 中检测 RTL 语言?
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)...
2024-08-25 Java开发问题
11

如何在 Java 中从 DB 加载资源包消息?
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)...
2024-08-25 Java开发问题
13

如何更改 Java 中的默认语言环境设置以使其保持一致?
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)...
2024-08-25 Java开发问题
13