<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属性,请大家帮忙看下,就是怎么样才能设置默认值

解决方案 »

  1.   

     <html:options value="<bean:write name='f' property='kindName'/>">
      

  2.   

    这样不可以啊,<html:options 没有value这个属性啊
      

  3.   

    记得好像Struts标签的value是不支持用<bean:write写的,因为value中的东西Struts标签会解析成字符串,也就是说这时这个标签的value根本就不是从数据库取出来的那个值,而是"<bean:write name='f' property='kindName'/>"这样一个字符串,等页面打开你可以看下页面的源码,看是不是这种情况,用<%=%>的写法才能解析成你要的。可以先用<bean:define来定义,写法和bean:write一样,多需要一个id属性,这个id属性就是起个变量名,然后在<%=%>中可以取到该变量名的值。
      

  4.   


      <html:option value="aaa"></html:option>
      

  5.   


    <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>这样也还是不可以啊
      

  6.   

    看下打开的页面的源码,select的值,与每个option的值,有相同的吗?
      

  7.   

    <html:options collection="kindList" property="kindName">
    <bean:write name='f' property='kindName'/></html:options> 或 <html:option value="<bean:write name='f' property='kindName'/>"> </html:option>
      

  8.   

    没有一样的怎么能设置成默认某个option为选中状态呢?
      

  9.   

    select的值是不是数据库取出来的值了?如果是,option中必须有且仅有一个与这个值相同时才会被默认选中,也就是你说的select的默认值设置成功了。
      

  10.   

      <script type="text/javascript">
        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>
      

  11.   

    <c:forEach items="${roles}" var="role">
    <html:multibox property="roleIds" value="${role.id}"></html:multibox>${role.name }&nbsp;
    </c:forEach>
    使用multibox,在你的form中设置的kindName的值,这样选中就是默认值
      

  12.   


    是的用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>
                 
      

  13.   

    用multibox?LZ要下拉框,你给改成复选框了?
    看LZ的代码我总觉得少点什么,<html:options>还少个labelProperty属性吧,不然你的下拉框没显示的文字,从表面上看不出来是哪个被选中。
      

  14.   

    不好意思,刚才写错啦!
    //  准备数据
    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>
    我试验了下,是可以的。楼主试下看看
      

  15.   

    哎 真无语 竟然没分?LZ你搞没搞错?我先提出你的options里少labelProperty属性的,而且从头到尾都一直在关注你这个问题,真没良心!