title: Custom JSP tag file <%@ variable ..> doesn't work?
body: <p>I want to define a custom JSP tag, which produces a HTML table with alternating row background colors. Therefore the CSS classes "odd" and "even" are set depending on the row index of the table.</p>
  
  <p>The example without the JSP tag works fine and the question is: What's going wrong in the custom tag example below? How can I  pass the variable "rowIndex" through both custom tags?</p>
  
  <p>The reference <a href="http://docs.oracle.com/javaee/1.4/tutorial/doc/JSPTags5.html" rel="nofollow">http://docs.oracle.com/javaee/1.4/tutorial/doc/JSPTags5.html</a> doesn't help.</p>
  
  <p>Thanks</p>
  
  <p><strong>Example JSP page that works:</strong></p>
  
  <pre><code>&lt;c:set var="rowIndex" value="1"/&gt;
  &lt;table class="datatable"&gt;
      &lt;tbody&gt;
          &lt;tr class="${(rowIndex %2 == 0) ? 'odd' : 'even'}"&gt;&lt;c:set var="rowIndex" value="${rowIndex+1}"/&gt;
              &lt;td width="200px"&gt;&lt;bean:message key='myKey' /&gt;&lt;/td&gt;
              &lt;td&gt;todoValue&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr class=${(rowIndex %2 == 0) ? 'odd' : 'even'}&gt;&lt;c:set var="rowIndex" value="${rowIndex+1}"/&gt;
              &lt;td&gt;&lt;bean:message key='myKey' /&gt;&lt;/td&gt;
              &lt;td&gt;todoValue&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p><strong>Example JSP page with custom tag that doesn't work:</strong></p>
  
  <p>JSP page</p>
  
  <pre><code>&lt;%@taglib tagdir="/WEB-INF/tags" prefix="myApp"%&gt;
  
  ....
  
  &lt;myApp:keyValueDataTable&gt;
      &lt;myApp:keyValueDataTableRow /&gt;
      &lt;myApp:keyValueDataTableRow /&gt;
      &lt;myApp:keyValueDataTableRow /&gt;
  &lt;/myApp:keyValueDataTable&gt;
  </code></pre>
  
  <p>dataTable.tag</p>
  
  <pre><code>&lt;%@ include file='/tiles/taglibs.inc'%&gt;
  &lt;%@tag description="Description" pageEncoding="UTF-8"%&gt;
  
  &lt;%@ variable name-given="rowIndex" %&gt; 
  &lt;c:set var="rowIndex" value="1" /&gt;
  
  &lt;table class="datatable"&gt;
      &lt;tbody&gt;
          &lt;jsp:doBody/&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>tableRow.tag</p>
  
  <pre><code>&lt;%@ include file='/tiles/taglibs.inc'%&gt;
  &lt;%@tag description="Description" pageEncoding="UTF-8"%&gt;
  
  &lt;%@ variable name-given="rowIndex" %&gt; 
  
          &lt;tr class="${(rowIndex %2 == 0) ? 'odd' : 'even'}"&gt;
              &lt;c:set var="rowIndex" value="${rowIndex+1}" /&gt;
              &lt;td width="200px"&gt;&lt;c:out value="Index=${rowIndex}"&gt;&lt;/c:out&gt; &lt;bean:message key='myKey' /&gt;&lt;/td&gt;
              &lt;td&gt;todoValue&lt;/td&gt;
          &lt;/tr&gt;
  </code></pre>