Search code examples
javajspdisplaytag

How to append an image to a cell value conditionally in a table. Its in a JSP and im using display tags for the table


I have a data table displayed in a JSP using DisplayTags. One of the columns in the table is a 'Priority' column. If the priority is 1, i have to be able to display a red light beside it. Is there any straight forward way of doing this?

<display:column headerClass="tableHead" title="Priority" property="priority" sortable="false" />

I need to be able to show an image beside all cells with data value '1'.

Update: i still dont see the image even though it dosent give an exception.

<display:column headerClass="tableHead" title="Priority" property="priority" sortable="false" ><c:if test="${dispatchresults1.priority eq 1}"><img src="images/flashinglight4.gif"/></c:if> </display:column>

This is the top of my table.

    <display:table htmlId="dispatchtable1" id="dispatchresults1" name="packedNotDispatchedlist" pagesize="20" style="width:100%;text-align:left;font-size:10px" class="thinBorder" requestURI=""   export="true" >

Update: This is what worked for me finally.

<display:column headerClass="tableHead" title="Priority"  sortable="false" > 
<c:choose>
<c:when test="${dispatchresults1.priority eq 1}"><img src="images/flashinglight4.gif"/>
</c:when>
<c:otherwise >${dispatchresults1.priority}
</c:otherwise>
</c:choose>             
</display:column>

Solution

  • <display:column headerClass="tableHead" title="Priority" sortable="false">
        <c:if test="${tableId.priority == 1}"><img src="..."/></c:if>
    </display:column>