JSTL1.1 的 forEach標簽能在JSF標簽中直接使用.
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> //導入的是JSTL 1.1 core Library
......
<table>
<tr>
<th>Item Name</th>
</tr>
<c:forEach items="#{frames.showKind}" var="k"> //item=List類型
<tr>
<td><h:outputText value="#{k.nowsum}" /><td>
</tr>
</c:forEach>
</table>
......
bean:
//用forEach循環中控制控件,會多次調用 items 方法訪問數據庫,所以需定義一個判斷.
public List getShowKind() {
if (null==showKind){
showKind=appinfoshow.showAllKind();
}
return showKind;
}