Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nesting choose within choose using JSP taglibs

Tags:

java

html

jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<td colspan="1" width="100">
<c:choose>
  <c:when>
  </c:when>

  <c:when>
  </c:when>

  <c:when>
    <c:choose>
       <c:when></c:when><c:otherwise><c:when></c:when></c:otherwise>
    </c:choose>
  </c:when>

  <c:otherwise>
  </c:otherwise>
</c:choose>
</td>

Is there a limit to nesting choose within a choose, such as this?

EDIT: the JSP compiler keeps complaining I have NO end tag if I put another <c:when></c:when> within the otherwise.

like image 302
bouncingHippo Avatar asked Jan 16 '23 06:01

bouncingHippo


2 Answers

As far as I know there is an error:

<c:when>
    <c:choose>
        <c:when></c:when><c:otherwise><c:when></c:when></c:otherwise>
    </c:choose>
</c:when>

should be:

<c:when>
    <c:choose>
        <c:when></c:when>
        <c:otherwise></c:otherwise>
    </c:choose>
</c:when>

you cannot have a nested when tag inside otherwise directly, to do that you need another choose tag:

<c:when>
    <c:choose>
        <c:when></c:when>
        <c:otherwise>
            <c:choose>
                <c:when></c:when>
            </c:choose>
        </c:otherwise>
    </c:choose>
</c:when>
like image 146
Pedro Robles Avatar answered Jan 21 '23 07:01

Pedro Robles


The JSP will be translated to Java, where function will be created for each custom tag like this

private boolean _jspx_meth_c_005fwhen_005f0(javax.servlet.jsp.tagext.JspTag _jspx_th_c_005fchoose_005f0, javax.servlet.jsp.PageContext _jspx_page_context)
      throws java.lang.Throwable {
javax.servlet.jsp.PageContext pageContext = _jspx_page_context;
javax.servlet.jsp.JspWriter out = _jspx_page_context.getOut();
//  c:when
org.apache.taglibs.standard.tag.rt.core.WhenTag _jspx_th_c_005fwhen_005f0 = (org.apache.taglibs.standard.tag.rt.core.WhenTag) _005fjspx_005ftagPool_005fc_005fwhen_0026_005ftest.get(org.apache.taglibs.standard.tag.rt.core.WhenTag.class);
_jspx_th_c_005fwhen_005f0.setPageContext(_jspx_page_context);
_jspx_th_c_005fwhen_005f0.setParent((javax.servlet.jsp.tagext.Tag) _jspx_th_c_005fchoose_005f0);
// /index1.jsp(4,2) name = test type = boolean reqTime = true required = true fragment = false deferredValue = false expectedTypeName = null deferredMethod = false methodSignature = null
_jspx_th_c_005fwhen_005f0.setTest(((java.lang.Boolean) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${true}", java.lang.Boolean.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null, false)).booleanValue());
int _jspx_eval_c_005fwhen_005f0 = _jspx_th_c_005fwhen_005f0.doStartTag();
if (_jspx_eval_c_005fwhen_005f0 != javax.servlet.jsp.tagext.Tag.SKIP_BODY) {
  do {
    out.write("\r\n");
    out.write("  ");
    int evalDoAfterBody = _jspx_th_c_005fwhen_005f0.doAfterBody();
    if (evalDoAfterBody != javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN)
      break;
  } while (true);
}
if (_jspx_th_c_005fwhen_005f0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
  _005fjspx_005ftagPool_005fc_005fwhen_0026_005ftest.reuse(_jspx_th_c_005fwhen_005f0);
  return true;
}
_005fjspx_005ftagPool_005fc_005fwhen_0026_005ftest.reuse(_jspx_th_c_005fwhen_005f0);
return false;
}

Having nested functions will increase the function stack levels. By default JVM has decent stack size, and should cause any issue for you/

like image 20
Ramesh PVK Avatar answered Jan 21 '23 08:01

Ramesh PVK