0
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<td colspan="1" width="100">
<c:choose>
  <c:when>
    <c:choose>
       <c:when></c:when><c:otherwise>
    <c:when test="<%=\"F\".equals(result[1]) %>">
     <c:set var="checked"><%=result[0].equals("Y")%></c:set>
     <input type="checkbox" id="<%="ABC"+"$"+rows%>" name="<%="ABC"+"$"+rows%>" value="<%=String.valueOf(rows)%>" ${checked ? 'checked' : ''} onclick="someFunction(this)"/>
    </c:when></c:otherwise>
    </c:choose>
  </c:when>    
  <c:otherwise>
  </c:otherwise>
</c:choose>
</td>

For some reason, the JSP compiler complains that there is no end tag for the <c:when> that nests the input type="checkbox"...may i know what i'm doing wrong? i tried using <c:if> and it doesnt work either, compiler complains no end tag too.

EDIT: if i dont nest the input type and the set var like below, then it works...but it fails to accomplish my original logic..

    <c:otherwise>
            <c:when test="<%=\"F\".equals(result[1]) %>">
            </c:when>
            <c:set var="checked"><%=result[0].equals("Y")%></c:set>
             <input type="checkbox" id="<%="ABC"+"$"+rows%>" name="<%="ABC"+"$"+rows%>" value="<%=String.valueOf(rows)%>" ${checked ? 'checked' : ''} onclick="someFunction(this)"/>
    </c:otherwise>

EDIT 2: i have to code jsp in this manner on pain of death from my architect lol. any advice will be gladly accepted to retain my proposed logic.

bouncingHippo
  • 5,940
  • 21
  • 67
  • 107
  • 1
    Why are you mixing 2 completely different ways of writing JSPs? Use either taglibs/EL, or oldschool *scriptlets*, not both. – BalusC Jun 28 '12 at 18:33
  • i have to code jsp in this manner on pain of death from my architect lol. also because thats how the system is set up to query the database any advice will be gladly accepted to retain my proposed logic. – bouncingHippo Jun 28 '12 at 18:38

1 Answers1

1

Just get rid of all those scriptlets (the oldschool <% %> things). They don't mix well with taglibs. The JSTL attributes take EL expressions only.

E.g., assuming that you've done a request.setAttribute("results", results) beforehand, which designtechnically needs to be done in a servlet, but can also be done in a scriptlet somewhere in top of JSP.

<c:forEach items="${results}" var="result">
  ...
  <td colspan="1" width="100">
    <c:choose>
      <c:when>
        <c:choose>
          <c:when></c:when>
          <c:otherwise>
            <c:when test="${result[1] == 'F'}">
              <c:set var="checked">${result[0] == 'Y'}</c:set>
              <input type="checkbox" id="ABC$${rows}" name="ABC$${rows}" value="${rows}" ${checked ? 'checked' : ''} onclick="someFunction(this)" />
            </c:when>
          </c:otherwise>
        </c:choose>
      </c:when>    
      <c:otherwise>
      </c:otherwise>
    </c:choose>
  </td>
  ...
</c:forEach>

It's instantly also much better readable this way.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555