- Java code
<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 >中就行
------解决方案--------------------
- Java code
<%@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>