kitokid
kitokid

Reputation: 3117

c choose tag with display tag table

I want to check a certain condition within a display tag table and show or not show the particular column.

<display:table class="displayTable" id="ItemList" 
    name="${sessionScope.myList}" requestURI="list.action" 
    pagesize="15" defaultsort="2" defaultorder="ascending" sort="list">
    <c:choose>
        <c:when test="${(loginUserOrgId > 0) and (loginUserOrgId==ItemList.organisationid)}">
            <display:column class="colOp" href="edit.action" paramId="itemId"
                 paramProperty="itemId">Edit</display:column>
        </c:when>
    </c:choose>
</display:table>

But it never shows the Edit link. When I print out the value with c:out, it is TRUE. but the Edit column doesn't display although the condition is true.

 <c:out value='${(loginUserOrgId > 0) and (loginUserOrgId==ItemList.organisationid)}'/>

Any missing point?

Upvotes: 0

Views: 3120

Answers (1)

tusar
tusar

Reputation: 3424

<c:out value='${(loginUserOrgId > 0) and (loginUserOrgId==ItemList.organisationid)}'/>

is printing TRUE.

But does it print true when you use this one ?

<c:if test='${loginUserOrgId > 0 && loginUserOrgId==ItemList.organisationid}'/>
     true
</c:if>

Always use && operator for conditional AND checking in JSTL

Also you have only one if-checking. You have no else condition. So why not use simpler <c:if> tags like this :

<display:table class="displayTable" id="ItemList" 
    name="${sessionScope.myList}" requestURI="list.action" 
    pagesize="15" defaultsort="2" defaultorder="ascending" sort="list">

    <c:if test="${loginUserOrgId > 0 && loginUserOrgId == ItemList.organisationid}">
        <display:column class="colOp" href="edit.action" paramId="itemId"
             paramProperty="itemId">Edit</display:column>
    </c:if>
</display:table>

Use <c:choose> only when you need if---else if---else like condition checking.

<c:choose> 
    <c:when test="${condition}">
         true value
    </c:when>
    <c:otherwise>
         false value
    </c:otherwise>
</c:choose>

Upvotes: 1

Related Questions