JSTL の <c:forEach> は、strutsタグの <logic:iterate> に比べて格段に便利だ。最もその差を感じるのが、ループ内で扱えるステータス変数の扱いやすさ。
<c:forEach> のステータス変数が持つプロパティの一覧。
| プロパティ | 機能 | 初期値 |
|---|---|---|
| varStatus.index | ループインデックス | 0 |
| varStatus.count | カウント値 | 1 |
| varStatus.first | 最初の要素かどうかの真偽値 | |
| varStatus.last | 最後の要素かどうかの真偽値 | |
| varStatus.begin | begin属性値(開始値) | |
| varStatus.end | end属性値(終了値) | |
| varStatus.step | step属性値(増分) | |
| varStatus.current | 現在値 |
first とか last とか、かゆいところに手が届いていて嬉しい。贅沢を言えるなら、perl の HTML::Template にあるような odd や even プロパティなんかあると、テーブルの縞模様とか二段組がカンタンに作れるのにね。
使用例とか。
strutsの場合。
<bean:size name="form" property="datalist" id="datanum" />
<logic:iterate name="form" property="datalist" id="data" indexId="loop">
<logic:equal name="loop" value="0">
// ループ1回目だけの処理
</logic:equal>
<bean:write name="data" property="name" />
<logic:equal name="loop" value="<%= String.valueOf(datanum.intValue()-1) %>">
// ループの最後だけの処理
</logic:equal>
</logic:iterate>
これと同じことをJSTLで。
<c:forEach items="${form.datalist}" var="data" varStatus="loop">
<c:if test="${loop.first}">
// ループ1回目だけの処理
</c:if>
<c:out value="${data.name}" />
<c:if test="${loop.last}">
// ループの最後だけの処理
</c:if>
</c:forEach>
いい感じ。
このエントリーのトラックバックURL
http://www.deftrash.com/admin/mt4/mt-tb.cgi/298

As someone who built and supports 29,000 1:1 VDI instances I agree with some of your statements but not all of them. While 3 years ago storage was absolutely the bottleneck the reality is that these days I’m more concerned with CPU and RAM consumption with newer application sets. For instance a running instance of Lync 2013 consumes 150mb of RAM as compared to Lync 2010 which consumed 25 mb. Across the board that’s a substantial increase that is difficult to account for. Server-based application delivery solutions alleviate that but with an added cost in both usability and infrastructure.