浏览 18885 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-01-30
最后修改:2009-01-30
使用<s:select>一直报错: tag 'select', field 'list', name 'supplierId': The requested list key '#product.getComPanys' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location] 我分别采用了4中方法:上面报错只是其中一种,但4中方法报错都一致。。。我google、baidu了 看了N多贴依然是解决不了超级郁闷,还请给位多指教!!! 下面贴出我的类以及处理方法: ProductAction package model.activion; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import model.service.CompanyService; import model.service.ProductService; import org.springframework.beans.factory.annotation.Autowired; import util.UtilRandow; import util.UtilString; import com.opensymphony.xwork2.ActionSupport; import entity.Company; import entity.Product; @SuppressWarnings("serial") public class ProductAction extends ActionSupport { @Autowired private ProductService productService; @Autowired private CompanyService companyService; private String productNo; private String productName; private String supplierId; private List<Company> comPanys; [color=red]//第一种与第二种都采用List赋值[/color] private HashMap mapCom; [color=red]//第三种 才偶那个Map赋值[/color] //保存产品 public String saveProduct(){ Product product = new Product(); product.setProductNo("CP"+UtilRandow.getDateRandow()); product.setProductName(productName); product.setSupplierId(supplierId); boolean falge = productService.addProduct(product); if (falge==true) return SUCCESS; else return ERROR; } public String getProductNo() { return productNo; } public void setProductNo(String productNo) { this.productNo = productNo; } public String getProductName() { return productName; } public void setProductName(String productName) { this.productName = productName; } public void setSupplierId(String supplierId) { this.supplierId = supplierId; } public String getSupplierId() { return supplierId; } [color=red]//Map 取值方法获取数据库种所有的company [/color] public HashMap getMapCom() { List<Company> ls = this.companyService.queryCompany(null, null); for(Company c :ls){ mapCom.put("companyId",c.getCompanyId()); mapCom.put("companyName", c.getCompanyName()); } return mapCom; } public void setMapCom(HashMap mapCom) { this.mapCom = mapCom; } [color=red]//List 取值方法获取数据库种所有的company [/color] public List<Company> getComPanys() { List<Company> comPanys = new ArrayList<Company>(); comPanys = this.companyService.queryCompany(null, null); return comPanys; } public void setComPanys(List comPanys) { this.comPanys = comPanys; } } UtilBean:只是其中一个方法有使用 //第四种采用<s:bean>的方式赋值 package model.bean; import java.util.ArrayList; import java.util.List; import model.service.CompanyService; import org.springframework.beans.factory.annotation.Autowired; import util.UtilString; import entity.Company; public class UtilBean { @Autowired private CompanyService companyService; private List<Company> lc = new ArrayList<Company>(); public List<Company> getLc() { List<Company> listCom = this.companyService.queryCompany(null, null); if (UtilString.isEmpty(listCom)) lc = null; else lc = listCom; return lc; } public void setLc(List<Company> lc) { this.lc = lc; } } Struts.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="model.activion" extends="struts-default"> <!-- 输入校验--> <action name="validateProduct" class="model.activion.ProductAction"> <result name="input">/jsp/product.jsp</result> </action> <action name="addProduct" class="model.activion.ProductAction" method="saveProduct"> <result name="success">/jsp/success.jsp</result> <result name="error">/jsp/error.jsp</result> <result name="input">/jsp/product.jsp</result> </action> </package> </struts> JSP界面:product.jsp <%@ page language="java" contentType="text/html; charset=UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <html> <head> <title>产品信息</title> <s:head theme="ajax"/> </head> <body> <center> <s:tabbedPanel id="productList" theme="ajax" doLayout="false" closeButton="pane" labelposition="top" selectedTab="product" > <s:div id="product" theme="ajax" label="基本信息"> <s:form action="validateProduct" validate="true"> <s:textfield name="productNo" label="产品编号" readonly="true" /> <s:textfield name="productName" label="产品名称" required="true" /> <!-- 第1种 List--> <s:select list="companys" listKey="companyId" listValue="companyName" name="supplierId" label="厂家名称" headerKey="" headerValue="" /> <!-- 第2种 List--> <s:action name="product" id="getComPanys" /> <s:select list="#product.getComPanys" listKey="companyId" listValue="companyName" name="supplierId" label="厂家名称" headerKey="" headerValue="" /> <!-- 第3种 Map--> <s:select list="mapCom" key="companyId" value="companyName" name="supplierId" label="厂家名称" headerKey="" headerValue="" /> <!-- 第4种 List--> <s:bean id="ub" name="model.action.UtilBean" /> <s:select list="#ub.lc" listKey="companyId" listValue="companyName" name="supplierId" label="厂家名称" headerKey="" headerValue="" /> <s:submit value="确定" action="addProduct" /> <s:reset value="重置" /> </s:form> </s:div> <!-- 图片上传未处理 --> <s:div id="image" theme="ajax" label="图片上传"> <s:form> <s:textfield name="productName" label="产品名称"/> <s:file name="file" accept="jpeg/gif/*" label="图片一"/> <s:file name="file" accept="jpeg/gif/*" label="图片二"/> <s:file name="file" accept="jpeg/gif/*" label="图片三"/> <s:submit value="上传" /> <s:reset value="重置" /> </s:form> </s:div> </s:tabbedPanel> </center> </body> </html> 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2009-01-30
最后修改:2009-01-30
实体类:
供应商:company package entity; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import org.hibernate.annotations.GenericGenerator; @Entity @Table(name = "bsc_company", catalog = "jxc_db") public class Company implements java.io.Serializable { // Fields private String companyId; private String companyNo; private String companyName; @GenericGenerator(name = "generator", strategy = "uuid.hex") @Id @GeneratedValue(generator = "generator") @Column(name = "company_id", unique = true, nullable = false, length = 50) public String getCompanyId() { return this.companyId; } public void setCompanyId(String companyId) { this.companyId = companyId; } @Column(name = "company_no", length = 50) public String getCompanyNo() { return this.companyNo; } public void setCompanyNo(String companyNo) { this.companyNo = companyNo; } @Column(name = "company_name", length = 50) public String getCompanyName() { return this.companyName; } public void setCompanyName(String companyName) { this.companyName = companyName; } } |
|
返回顶楼 | |
发表时间:2009-01-30
最后修改:2009-01-30
首先保证;
List<Company> listCom = this.companyService.queryCompany(null, null); 返回一定有值!!! |
|
返回顶楼 | |
发表时间:2009-02-01
总结的好!
|
|
返回顶楼 | |
发表时间:2009-04-10
在第一种list=companys改成list=%{companys}试试。
|
|
返回顶楼 | |
发表时间:2009-04-12
谢谢 楼上兄弟 我试试看 !!!
|
|
返回顶楼 | |