<html:select><html:optionsCollection>中怎么取得数据库中对应值?
[/color]我在jsp页面中用了:
<html:select property="custLevelLabel" value="${customer.custLevelLabel}" size="1">
<html:optionsCollection name="level" label="dictItem" value="dictId"/>
</html:select>
用于取得数据库中数据库中数据,这点已经实现,已经把一列值取出并放入下拉列表。
这是一个编辑页面,也就是从一个列表页面跳转到这个页面(编辑页面代码如下):
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
<html:base />
<title>客户信息</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" style="max-width: 100%;height: auto;width: auto\9;" src="http://www.reader8.com/../scripts/js/common.js"></script>
<link rel="stylesheet" href="../../../styles/css/style.css" type="text/css"></link>
<script type="text/javascript">
function showMessage(){
var msg=document.getElementById("lnkmsg").value;
showMsg(msg);
}
</script>
</head>
<body onload="showMessage();">
<div method="post">
<div styleonclick="help('');">帮助</html:button>
<html:button property="" styleonclick="to('linkman.do?id=${custId}');">联系人</html:button>
<html:button property="" styleonclick="to('activity.do?id=${custId}');">交往记录</html:button>
<html:button property="" styleonclick="to('orders.do?id=${custId}');">历史订单</html:button>
<html:button property="" styleonclick="back();">返回</html:button>
<html:submit property="submit" stylevalue="${customer.custName}"></html:text><span value="${customer.custRegion}">
<html:optionsCollection name="region" label="dictItem" value="dictId"/>
</html:select>
<th>客户经理</th>
<td>
<html:select property="custManagerName" value="${customer.custManagerName}" size="1">
<html:optionsCollection name="mamager" label="usrName" value="usrId"/>
</html:select>
</td>
</tr>
<tr>
<th>客户等级</th>
<td>
<html:select property="custLevelLabel" value="${customer.custLevelLabel}" size="1">
<html:optionsCollection name="level" label="dictItem" value="dictId"/>
</html:select>
</td>
<th></th>
<td></td>
</tr>
<tr>
<th>客户满意度</th>
<td>
<html:select styleId="Satisfy" property="custSatisfy" size="1">
<html:option value="0">未指定</html:option>
<html:option value="5">☆☆☆☆☆</html:option>
<html:option value="4">☆☆☆☆</html:option>
<html:option value="3">☆☆☆</html:option>
<html:option value="2">☆☆</html:option>
<html:option value="1">☆</html:option>
</html:select>
</td>
<th>客户信用度</th>
<td>
<html:select styleId="Credit" property="custCredit" size="1">
<html:option value="0">未指定</html:option>
<html:option value="5">☆☆☆☆☆</html:option>
<html:option value="4">☆☆☆☆</html:option>
<html:option value="3">☆☆☆</html:option>
<html:option value="2">☆☆</html:option>
<html:option value="1">☆</html:option>
</html:select>
</td>
</tr>
</table>
<br />
<table id="table1">
<tr>
<th>地址</th>
<td><html:text property="custAddr" value="${customer.custAddr}"></html:text><span value="${customer.custZip}"></html:text><span value="${customer.custTel}"></html:text><span value="${customer.custFax}"></html:text><span value="${customer.custWebsite}"></html:text><span id="table2">
<tr>
<th>营业执照注册号</th>
<td><html:text property="custLicenceNo" value="${customer.custLicenceNo}"></html:text></td>
<th>法人</th>
<td><html:text property="custChieftain" value="${customer.custChieftain}"></html:text><span value="${customer.custBankroll}"></html:text> </td>
<th>年营业额</th>
<td>
<html:text property="custTurnover" value="${customer.custTurnover}"></html:text>
</td>
</tr>
<tr>
<th>开户银行</th>
<td>
<html:text property="custBank" value="${customer.custBank}"></html:text><span value="${customer.custBankAccount}"></html:text><span value="${customer.custLocalTaxNo}"></html:text></td>
<th>国税登记号</th>
<td><html:text property="custNationaltaxno" value="${customer.custNationalTaxNo}"></html:text></td>
</tr>
</table>
</logic:present>
</html:form>
<input type="hidden" id="lnkmsg" value="${msg}">
</body>
</html:html>
其他的内容都能够从数据库读出,并正确显示,但就是那几个下拉列表不知如何让它选中数据库原有的对应值
请哪位高手解决一下,小弟万分感激。
昨天有位朋友说属性要与FormBean中的字段相同,我查了的
是相同的
而且,其他那些字段都能显示,就是那几个下拉列表不能选中对应数据库的值
[color=red]诸位的方法我都试过了
还是不行
关键我是先从其它表中读进一个集合
然后根据另一张表的信息而显示选中的具体内容 <column name="cust_region" length="50" />
</property>
<property name="custManagerName" type="java.lang.String">
<column name="cust_manager_name" length="50" />
</property>
<property name="custLevelLabel" type="java.lang.String">
<column name="cust_level_label" length="50" />
</property>
........
FormBean内容如下:
.......
private String custRegion;
private String custManagerName;
private String custLevelLabel;
........
数据库有值,而且其它字段能够显示.
我检查了很多遍了,字段名数据类型都是对的.
可是还没有办法解决.
如果各位觉得还要什么资料我再写上来.
<html:option value="">请选择...</html:option>
<html:optionsCollection name="region" label="dictItem"
value="dictItem"/>
</html:select>
<th>
客户经理
</th>
<td>
<html:select property="custManagerName" value="${customer.custManagerName}" size="1">
<html:option value="">请选择...</html:option>
<html:optionsCollection name="mamager" label="usrName"
value="usrName" />
</html:select>
</td>
</tr>
<tr>
<th>
客户等级
</th>
<td>
<html:select property="custLevelLabel" value="${customer.custLevelLabel}" size="1">
<html:option value="">请选择...</html:option>
<html:optionsCollection name="level" label="dictItem"
value="dictItem" />
</html:select>
</td>
<th></th>
<td></td>
</tr>
我觉得问题出于 html:optionsCollection 中对应 value属性设置的问题。
value 一定要对应当前下拉列表的值。
还是谢谢上面的朋友。