C:forEach

From OpenCms Wiki
Jump to: navigation, search

This tag is of course documented in a lot of other places, but since it is used extensively for openCMS development, I feel taht it has its use to be put here also.

If you have included the jstl core tag lib like this:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

you can use the c:forEach tag

<c:forEach var="yourItemOfCollectionVarName" items="${yourCollection}" varStatus="yourStatus">
   <!-- your code goes here -->
</c:forEach>

varStatus

If you like to do something different for every x row or only for the last or first row, varStatus is helping a lot. The optional varStatus variable has some useful properties to help you on this:

  • current
  • index
  • count
  • first
  • last
  • begin
  • step
  • end

Example:

<c:forEach var="yourItemOfCollectionVarName" items="${yourCollection}" varStatus="yourStatus">
   <div id="line-${yourStatus.index}">${yourItemOfCollectionVarName.name}</div>
</c:forEach>
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox