<select id="goodsTypeId" >
<s:iterator id="gType" value="#request.listGoodsTypeData" status="index">
<option id="${index}" <c:if test="${gdType.id == 3} "> selected="true" </c:if> >${gType.name }</option>
        </s:iterator>
        </select>这里面的C:IF完全无效.请问是什么原因原本的判断应该是这样的
 <c:if test="${gdType.id == goodsData.goodsTypeId}">
两个ID值是必然有相当的.但是却没有效果.如果单独拿出来不在<s:iterator >中就行

解决方案 »

  1.   

    <c:if test="${gdType.id} == ${goodsData.goodsTypeId}">
      

  2.   

    回heardy.
    这样效果也是一样.
    连<c:if test="${gdType.id == 3} ">都没有.可以确定的是gdType.id里面是有3这个值的
      

  3.   


    <select id="goodsTypeId" >
        <s:iterator id="gType" value="#request.listGoodsTypeData" status="index">
        <option id="${index}"
           <c:if test="${gdType.id == 3} "> selected="true" </c:if> >${gType.name }</option>
        </s:iterator>
    </select>
      

  4.   


    <select id="goodsTypeId" >
        <s:iterator id="gType" value="#request.listGoodsTypeData" status="index">
        <option id="${index}"
           <c:if test="${gdType.id == 3} "> selected="true" </c:if> >${gType.name }</option>
        </s:iterator>
    </select>
    id="gType"  和gdType.id  是不是同一个啊?是否是这边的引起的?
      

  5.   

    回creso  标签已经引入
    回heardy   gdType.id是我在<s:iterator>外部试的时候用的名字.不小心弄错的.
      现在我换成了gType.id C:IF还是无用!>
    请问谁遇到过这种情况么?
      

  6.   

    上面的gdType应该是在值栈里的~
    建议换成s:if标签
      

  7.   

    还有就是如果C:IF单独放在外部就可以用.我用来判断男女时就可以​代码如下<input value="1" type="radio"  <c:if test="${mtUser.sex  ==1 }">checked="true"
    </c:if> name="sex" />男
    <input value="0"type="radio"  <c:if test="${mtUser.sex  ==0 }">checked="true"
    </c:if> name="sex" />女</td>
    回creso         S:IF也用过,一样无效.而且对于网页来说C;IF比S:IF要好
      

  8.   

    c:if  不能内嵌到html标签中使用,struts的可以,既然用了s:iterator  为何不用 s:if  ???? 
      

  9.   

    回ch656409110
    据说是S:IF对页面的负担比较大.所以说不让用.
    现在我也把<s:iterator>换成了<c:forEach>
    就是不出结果
      

  10.   


    <%@page import="java.util.ArrayList"%>
    <%@page import="java.util.List"%>
    <%@page import="org.heardy.bean.BasicBean"%>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="/struts-tags" prefix="s"%>
    <%@   taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%
    BasicBean basicBean1 = new BasicBean();
    basicBean1.setId(1);
    BasicBean basicBean2 = new BasicBean();
    basicBean2.setId(2);
    BasicBean basicBean3 = new BasicBean();
    basicBean3.setId(3);
    BasicBean basicBean4 = new BasicBean();
    basicBean4.setId(4);
    List<BasicBean> l = new ArrayList<BasicBean>();
    l.add(basicBean1);
    l.add(basicBean2);
    l.add(basicBean3);
    l.add(basicBean4);
    request.setAttribute("list", l);
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <select id="goodsTypeId">
    <s:iterator id="gType" value="#request.list" status="index">
    <option id="${index}"
    <c:if test="${gType.id eq 4}"> ' selected=true ' </c:if>>${gType.id
    }</option>
    </s:iterator>
    </select>
    </body>
    </html>
    这个是我这边调试的效果,你应该要这样的效果吧!
      

  11.   

    这 
    <c:if test="${gdType.id == 3} "> selected="true" </c:if>
    改成
    <c:if test="${gType.id eq 3}"> selected="true" </c:if>
    应该就可以了
      

  12.   

    回heardy
    eq我早试过了的,没效果.!
    你调试下来可以?
      

  13.   

    回lvbang_lzt我现在就是在测试死数据,
    代码是没问题的,值也能取出来.只不过不能选中...
      

  14.   

    id="gType"     和  gdType.id
      

  15.   

    对比了下<c:if test="${gType.id eq 4}"> ' selected=true ' </c:if>>
            <c:if test="${gType.id eq 3} "> selected="true" </c:if> >
    难道是引号的问题?
      

  16.   

    <%@page import="java.util.ArrayList"%>
    <%@page import="java.util.List"%>
    <%@page import="org.heardy.bean.TestBean"%>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="/struts-tags" prefix="s"%>
    <%@   taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%
    TestBean basicBean1 = new TestBean();
    basicBean1.setId(1);
    basicBean1.setName("a");
    basicBean1.setName("1");
    TestBean basicBean2 = new TestBean();
    basicBean2.setId(2);
    basicBean2.setName("ba");
    basicBean2.setName("2");
    TestBean basicBean3 = new TestBean();
    basicBean3.setId(3);
    basicBean3.setName("c");
    basicBean3.setName("3");
    TestBean basicBean4 = new TestBean();
    basicBean4.setId(4);
    basicBean4.setName("d");
    basicBean4.setName("4");
    List<TestBean> l = new ArrayList<TestBean>();
    l.add(basicBean1);
    l.add(basicBean2);
    l.add(basicBean3);
    l.add(basicBean4);
    request.setAttribute("list", l);
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <select id="goodsTypeId">
    <s:iterator id="gType" value="#request.list" status="index">
    <option id="${index}"
    <c:if test="${gType.name == 2}"> selected="true" </c:if>>${gType.name
    }</option>
    </s:iterator>
    </select>
    </body>
    </html>
    我把它改成String 也可以实现诶!
    你最好先吧这些数据都遍历一下看看,能否都可以打印
      

  17.   

    回 heardy
    感谢你的帮助.我对比了下.我们的代码基本没什么区别.
    我在想是浏览器还是框架的原因.感谢你
      

  18.   

    <c:if test="${gdType.id == 3} "> 
    注意:"${gdType.id == 3} "
    中间不要加空格试试
    变成
    <c:if test="${gType.id == 3}" >