新手求教关于c:if标签
<select name="lanmu" id="lanmu">
<logic:notEmpty name="lmlist">
<logic:iterate id="list" name="lmlist">
<c:if test="${list.id eq newspaer.lanmuId}">
<option value="${list.id}" selected="selected">${list.name}</option>
</c:if> <option value="${list.id}">${list.name}</option>
</logic:iterate>
</logic:notEmpty>
</select>
list集合正在用logic标签迭代的存放在session里的变量lmlist的别名,
newspaper是一个实例对象,也存在session内,lanmuId是他一个属性,
现在的需求是在list迭代到某条记录时候id与newspaper的lanmuId相等的时候,
此option标记为selected.上述代码无效,求教.
------解决方案--------------------<select name="lanmu" id="lanmu">
<logic:notEmpty name="lmlist">
<logic:iterate id="list" name="lmlist">
<option value="${list.id}" <c:if test="${list.id eq newspaer.lanmuId}">selected="selected" </c:if>>${list.name}</option>
</logic:iterate>
</logic:notEmpty>
</select>
直接把selected="selected" 给<c:if>起来就可以了
------解决方案--------------------
将id先取出来,不要放到循环中,
<c:set var="lanmuId" value="${newspaer.lanmuId}" />
然后
<c:if test="${list.id == lanmuId}">
</c:if>