kitokid
kitokid

Reputation: 3117

display tag and c choose tag

I use the following code. But it is always go to the otherwise condition. I checked the value , and those are correctly passed from java to the jsp. Any missing points?

<c:when test="${pCount > 0}">
    <display:column class="colPCount" property="pCount " title="${titlePCount}" sortable="true" headerClass="sortable" />
</c:when>
<c:otherwise>
    <display:column class="colPCount" title="${titlePCount}">&nbsp;-&nbsp;</display:column>
</c:otherwise>

For the pcount>0 items, still displaying as '-' in the display tag. Even I reverse the checking condition like pCount<0 in the first condition checking, the display tag always show the otherwise condition. It always pointing to the otherwise condition for every value.

Edited: Full Code

    <display:table class="displayTable" id="itemList"
        name="${sessionScope.itemList}" requestURI="listItem.action"
        pagesize="15" defaultsort="2" defaultorder="ascending" sort="list">
        <display:column class="colItemName" property="name"
            title="${titleItemName}" sortable="true" headerClass="sortable"/>
        ...
        <c:choose>
        <c:when test="${pCount > 0}">
            <display:column class="colPCount" property="pCount " title="${titlePCount}" sortable="true" headerClass="sortable" />
        </c:when>
        <c:otherwise>
            <display:column class="colPCount" title="${titlePCount}">&nbsp;-&nbsp;</display:column>
        </c:otherwise>
        </c:choose>
    </display:table>

Upvotes: 1

Views: 1749

Answers (3)

Alex
Alex

Reputation: 11579

Try this way: ${itemList.pCount>0}

Upvotes: 2

Beau Grantham
Beau Grantham

Reputation: 3456

I think you might be using the display tag library incorrectly.

It looks like what you are trying to do is to display row.pCount if the value is greater than zero, otherwise display -. But what you're actually doing is telling the library to display the entire column differently based on something (pCount, which probably does not exist in the scope you are referencing it... or you're going to have to show us some more code).

Try something like this:

<display:column class="colPCount" title="${titlePCount}" sortable="true" headerClass="sortable">
    <c:choose>
        <c:when test="${row.pCount > 0}">
            <c:out value="${row.pCount}" />
        </c:when>
        <c:otherwise>
            &nbsp;-&nbsp;
        </c:otherwise>
    </c:choose>
</display:column>

Upvotes: 0

Alex
Alex

Reputation: 11579

I guess that the variable pCount = null. Try to check ${not empty pCount and pCount>0}.

Upvotes: 0

Related Questions