在c:forEach与s:iterator里面使用if标签判断当前位置是否为2的倍数

c:forEach:

<c:forEach var="workflow" items="${workflowList}">
<tr
<c:if test="${workflowList.indexOf(workflow) % 2 == 0}"> class="lightTr"</c:if>>
<td><input type="checkbox" name="isWorkflow"
value="${workflow.workflowId}" />
</td>
<td><a
href="javascript:workflowAddorEdit('edit','${workflow.workflowId}')">${workflow.workflowName}</a>
</td>
</tr>
</c:forEach>
  1. 如果是set集合的时候呢?indexOf还能用吗?
  2. indexOf的下标从0开始,为了给第一行数据加入class,所以用了%2 == 0。

s:iterator:

<ul>
<li class="firstLi">
<input type="checkbox" id="ctlUserIds" onclick="wcmAppCommon.checkBox.selectAll(this,'catalogUserIds');"/>&nbsp;&nbsp;栏目名称</li>
<s:if test="catalogUserList.isEmpty()">
<li>暂无相关数据</li>
</s:if>
<s:iterator value="catalogUserList" id="catalogUser" status="i">
<li<s:if test="#i.count%2 != 0"> class="lightTr"</s:if>><input type="checkbox" name="catalogUserIds" value="<s:property value="#catalogUser.catalogUserId"/>"/>&nbsp;&nbsp;<s:property value="#catalogUser.catalog.catalogFullName"/>
</li>
</s:iterator>
</ul>
  1. s:iterator显然封装的更好。
  2. i.count 是从1开始的。

  3. 用s:if判断list是否为空

    <s:if test="catalogManageList.isEmpty()">`
    <li>暂无相关数据</li>
    </s:if>

    在s:iterator之前使用,因为s:iterator本身会判断是不是空才进去干活。

在c:forEach与s:iterator里面使用if标签判断当前位置是否为2的倍数的更多相关文章

  1. JSTL-core核心代码标签库中的forEach,remove, forTokens,choose,when,otherwise,redirect 标签

    <%@ page language="java" import="java.util.*, cn.hncu.domain.*" pageEncoding= ...

  2. 集合遍历元素的3种方法:for、foreach、迭代器iterator

    1.for循环方式(Set集合不能使用,因为Set是无序的没有索引) for (int i = 0; i < list.size(); i++) { Object o = list.get(i) ...

  3. LeetCode解题报告汇总! All in One!

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 把自己刷过的所有题目做一个整理,并且用简洁的语言概括了一下思路,汇总成了一个表格. 题目 ...

  4. 为什么iterator,foreach遍历时不能进行remove操作?除了一种情况可以这样(特殊情况)?

    Exception in thread "main" java.util.ConcurrentModificationException 并发修改异常引发的思考! 1 foreac ...

  5. for 、foreach 、iterator 三种遍历方式的比较

    习惯用法 for.foreach循环.iterator迭代器都是我们常用的一种遍历方式,你可以用它来遍历任何东西:包括数组.集合等 for 惯用法: List<String> list = ...

  6. JAVA中的for-each循环与迭代

    在学习java中的collection时注意到,collection层次的根接口Collection实现了Iterable<T>接口(位于java.lang包中),实现这个接口允许对象成为 ...

  7. 集合框架遍历方式之——for-each循环

    从Java5起,在Java中有了for-each循环,可以用来循环遍历collection和array.Foreach循环允许你在无需保持传统for循环中的索引,或在使用iterator /ListI ...

  8. YUI Array 之each| forEach(遍历)

    1. yui-each原码: 遍历YArray.each = YArray.forEach = Lang._isNative(Native.forEach) ? function (array, fn ...

  9. 使用Iterator遍历Sheet(POI)验证及解释结果有序性

    test.xlsx: Code: package poi; import static org.junit.Assert.*; import java.io.IOException; import j ...

随机推荐

  1. 【vue】移动端demo资料

    http://imzjh.com/inew/#/(移动端demo) https://github.com/liangxiaojuan/eleme(饿了么git地址) https://github.co ...

  2. python之pickle

    #!/usr/bin/python # -*- coding: UTF- -*- ''' ''' import pickle # pickle 只能Python识别 不适用于别的语言 li = [, ...

  3. Filebeat原理与简单配置入门

    Filebeat工作原理 Filebeat由两个主要组件组成:prospectors 和 harvesters.这两个组件协同工作将文件变动发送到指定的输出中. Harvester(收割机):负责读取 ...

  4. ES ik分词器使用技巧

    match查询会将查询词分词,然后对分词的结果进行term查询. 然后默认是将每个分词term查询之后的结果求交集,所以只要分词的结果能够命中,某条数据就可以被查询出来,而分词是在新建索引时指定的,只 ...

  5. PHP利用多进程处理任务

    PHP多进程一般应用在PHP_CLI命令行中执行php脚本,不要在web访问时使用.   多进程处理分解任务一般要比单进程更快.   php查看是否安装多进程模块: php -m | grep pcn ...

  6. CF908G New Year and Original Order 数位DP

    传送门 看到数据范围到\(10^{700}\)毫无疑问数位DP.那么我们最重要的问题是如何有效地维护所有数位排序之后的数的值. 对于某一个数\(x\),设\(f_{x,i} (i \in [1,9]) ...

  7. 【第二篇】ASP.NET MVC快速入门之数据注解(MVC5+EF6)

    目录 [第一篇]ASP.NET MVC快速入门之数据库操作(MVC5+EF6) [第二篇]ASP.NET MVC快速入门之数据注解(MVC5+EF6) [第三篇]ASP.NET MVC快速入门之安全策 ...

  8. Neutron:ML2 Core Plugin

    两个 Core Plugin:linux bridge plugin 和 open vswitch plugin.   Moduler Layer 2(ML2)是 Neutron 在 Havana 版 ...

  9. 控制结构(1): 分枝/叶子(branch/leaf)

    // 下一篇:卫语句(guard clause) 典型代码: function doSomething1(){ // ... } function doSomething2(){ // ... } f ...

  10. Jmeter录制手机app脚本

    转:http://www.cnblogs.com/yangxia-test/p/5484616.html   环境准备: 1.手机 2.wifi 3.Jmeter   具体步骤: 1.启动Jmeter ...