Java Ninja Chronicles By Norris Shelton

Things I learned in the pursuit of code

I have a JSP tag file named collapsiblePanel with the following attribute declaration for a JSP fragment.

<%@ attribute name="content" required="true" fragment="true"
              description="Passed as fragment, renders content1 inside of panel." %>

I am using the tag around some output to create a collapsed panel.

                <tags:collapsiblePanel id="principalsSection"
                                       heading="Principals (${fn:length(business.principals)} Found)">
                    <jsp:attribute name="content">
                        <c:if test="${not empty business.principals}">
                            <div class="jx-container">
                                <table class="jx-table">
                                        <c:forEach var="principal" items="${business.principals}" varStatus="status">
                                            <tr class="${jxp:rowClass(status)}">
                                                    ${} ${} ${}

The collapsible panel adds an arrow before the heading and makes the arrow and the headging a clickable area that will trigger the uncollapse. I did not want to add the arrow or the clickable area if there wasn’t anything to uncollapse. I tried to test for this by saying

<c:if test="${empty content}">

This is supposed to work, but in Glassfish 2.1.1 content contains the reference to the content fragment. I worked around this by:

<jsp:invoke var="content" fragment="content"/>
<c:if test="${empty content}">

This did the trick. I evaluated the JSP fragment and placed the result in a variable also named content. I was able to then act on it like a normal attribute.

April 3rd, 2012

Posted In: Java, JSP

One Comment

  • Foobie says:

    hi there,

    the empty-check of a fragment is problematic not only on glassfish… i am running a tomcat 7.0.x, where fragments sometimes contain whitespaces (despite trim=”true” on jsp:attribute), instead of being null. It’s a pitty, because the simple empty-check looks more elegant.
    thx for your solution anyway.

Leave a Reply

Your email address will not be published. Required fields are marked *

WP to LinkedIn Auto Publish Powered By :