struts2 <s:select>赋值方法

我的应用中,有个产品由哪个单位供应,所以在录入产品的时候供应商(厂家)希望是下来选择:
使用<s:select>一直报错:
[color=red][b]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][/b][/color]

我分别采用了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;
}
}



[color=red]UtilBean:只是其中一个方法有使用 //第四种采用<s:bean>的方式赋值[/color]

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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值