用value属性不行吗?我没试过
解决方案 »
- java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
- solr中去除重复记录
- 一个很让人头疼的错误,求帮忙
- 關于DWR同步設置的怪異問題
- 请教一个JAVA服务器思路
- httpunit的js问题
- dom4j解析带命名空间的问题
- java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver 如何是好啊!!!急啊
- JBoss-3.2.1中配置了datasource,为什么lookup不到啊?
- 如何用jsp实现图文混排在线等待,那位大哥帮帮忙!!!
- 一个关于JTable中编辑器的使用的问题,请多多指教(急!!在线等待,顶者有分哦)
- struts中如何限制上传文件的文件类型
<option value="id1">value1</option>
<option value="id2" selected>value2</option>
<option value="id3">value3</option>
</select>
例如:<html:form action="..">如果你的传到UserForm property userSecurity 属性 = "AA"
而此时集合groupList里有个对象obj的groupId属性也 = "AA" 则会自动选择到该项上
显示的内容为 obj对象的description属性
..
<html:select property="userSecurity">
<logic:present name="groupList">
<html:options collection="groupList"
property="groupId"
labelProperty="description"/>
</logic:present>
</html:select></html:form>
同时同意 枫的看法
下拉框的值就可以了啊
如果你需要重新reload数据,你当然也可以在server端实现。
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
ArrayList result = new ArrayList();
String sql = null;
try {
sql = "SELECT * FROM country ";
conn = connectionPool(req);
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while (rs.next()) {
LabelValueBean labelValue = new LabelValueBean(rs.getString(
"country_name"), rs.getString("id"));
result.add(labelValue);
}
}
catch (Exception ex) {
throw new StrutsException("read.error.database");
}
finally {
if (rs != null) {
rs.close();
}
if (ps != null) {
ps.close();
}
if (conn != null) {
conn.close();
} }
return result;
}
这是在execute方法中写的
if (type.equals("add")) {
ArrayList country_ary = new ArrayList();
try {
country_ary = showCountryName(req);
if (country_ary.size() > 0) {
req.setAttribute("country", country_ary);
return mapping.findForward("province.add.success");
}
else {
req.setAttribute("country", country_ary);
return mapping.findForward("province.add.fail");
}
}
catch (StrutsException ex) {
req.setAttribute("country", country_ary);
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError(ex.getMessage()));
saveErrors(req, errors);
return mapping.findForward("province.add.fail");
}
}
标签为:
<html:select name="provinceForm" property="countryID" style="width:150">
<html:option value="">please select</html:option>
<html:options collection ="country" property ="value" labelProperty ="label" />
</html:select>
provinceForm是form的名称,property是select的属性
传过来的值为coutry,这样就能正确显示