<html:select property="kindName" value="<bean:write name='f' property='kindName'/>">
<html:options collection="kindList" property="kindName" />
</html:select>为什么这样不可以啊,f是一个FlowerVo.java的引用,也含有kindName属性,该属性的值是从数据库中提取出来,现在就是想让下拉框的默认值为这个啊,但是不行,而kindList是一个含有Kind.java的一个list,Kind类含有kindName属性,请大家帮忙看下,就是怎么样才能设置默认值
<html:option value="aaa"></html:option>
<bean:define id="kkName" name="f" property="kindName"></bean:define>
<td>
<html:select property="kindName" value="<%=kkName%>">
<html:options collection="kindList" property="kindName" />
</html:select>这样也还是不可以啊
<bean:write name='f' property='kindName'/></html:options> 或 <html:option value="<bean:write name='f' property='kindName'/>"> </html:option>
function testSelect(){
var sele = document.getElementById("buttNum");
//3种方法自选
// 1,sele.value=sele.options(1).value;
// 2,sele.value="ccc";
//3,
sele.value=document.getElementById("DBvalue").value;
}
</script>
</head>
<body onload="testSelect()">
<html:form action="" name="form0">
<!-- value="ccc" value="aaa" 隐藏一个和 <html:option里面的一致就是你需要默认值:
value="<bean:write name='f' property='kindName'/>"
-->
<html:hidden property="DBvalue" id="DBvalue" value="bbb"></html:hidden>
<html:select value="buttNum" property="buttNum" id="buttNum">
<html:option value="aaa"></html:option>
<html:option value="bbb"></html:option>
<html:option value="ccc"></html:option>
</html:select>
<a onclick="testSelect()">点击test</a><br>
<html:multibox property="roleIds" value="${role.id}"></html:multibox>${role.name }
</c:forEach>
使用multibox,在你的form中设置的kindName的值,这样选中就是默认值
是的用struts logic 标签也可以
<html:select value="buttNum" property="buttNum" id="buttNum">//判断一form属性个值
<logic:equal property="kindName" value="123">
<html:option value="<bean:write name='f' property='kindName'/>"></html:option>
</logic:equal>
看LZ的代码我总觉得少点什么,<html:options>还少个labelProperty属性吧,不然你的下拉框没显示的文字,从表面上看不出来是哪个被选中。
// 准备数据
request.setAttribute("users", users);
UserForm formbean = (UserForm) form;
formbean.setUserid("3");//把默认值放到formbean中,显示 的自然就是默认值啦
//form表单对应的action//jsp页面
<html:form action="/user/manage">
<html:select property="userid">
<html:options collection="users" property="id" labelProperty="name"/>
</html:select>
</html:form>
我试验了下,是可以的。楼主试下看看