Search code examples
displaytag

Display Tag with Hidden Column: "Nothing Found to Display" has Wrong COLSPAN


We having a Display Table with a hidden column, 4 total (1 hidden):

<display:table id="row" pagesize="10" sort="list" style="table-layout:fixed;">
    <display:column title="id" class="hidden" headerClass="hidden">
                        ${row_rowNum - 1}
    </display:column>
    <display:column title="Other Info" >
                        ...
    </display:column>
    <display:column title="Other Info 2" >
                        ...
    </display:column>
    <display:column title="Other Info 3" >
                        ...
    </display:column>

When there's nothing to display, the HTML rendered is this:

<td colspan="3">Nothing found to display.</td>

But this is causing CSS issues for us, the table is misaligned. It should be ColSpan=4:

<td colspan="4">Nothing found to display.</td>

Why is the Empty Message ColSpan not counting the Hidden Column?

FYI, the CSS style "hidden" is:

.hidden {
    display: none;
}

Solution

  • The attribute class="hidden" just sets a (css)-class to "hidden", the column will nevertheless be printed in the HTML code.

    Example

    JSP

    <display:table name="mylist">
        <display:column class="hidden" property="id"/>
        <display:column property="name"/>
    </display:table>
    

    will produce the following HTML code:

    <table>
        <tr>
            <td class="hidden">ID#1</td>
            <td>NAME#1</td>
        </tr>
        ...
    </table>
    

    With your CSS (.hidden { display: none;}) you are only telling the browser to hide the first <td>-tags during display.

    Suggestion

    At an if/else construct in your jsp code to show your own error message.

    <%@ taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core' %>
    ...
    <c:choose>
        <c:when test="${empty mylist}">
            No data
        </c:when>
        <c:otherwise>
        <display:table name="mylist">...</display:table>
        </c:otherwise>
    </c:if>
    

    Maybe this is also an displaytag issue. Try to take a look into the newer development on Github, maybe this issue is solved there. But there is no active community as far as I remember.