Search code examples
javajspjstldisplaytag

How to add a condition to displaytag table with jstl


I want to generate a table with display tag. One of the column is a status type. And, this status type can be 1 or 0. (active or passive). Table is:

<display:table id="txt" name="student.homeworks" pagesize="20">
     <display:column property="homeworkId" title="Id"/>
     <display:column property="homeworkName" title="Homework Name" />
     <display:column property="studentName" title="Student Name" />
     <display:column title="Status">
          <c:if test="${statusType == '1'}">
            Active
          </c:if>
          <c:if test="${statusType == '0'}">
            Passive
          </c:if>
     </display:column>
</display:table>

"c" tag is JSTL. But, statusType is always coming as "NULL". I am trying many ways. How to check this parameter correctly?


Solution

  • The documentation of the table tag says:

    id - See "uid".

    uid - Unique id used to identify this table. The object representing the current row is also added to the pageContext under this name, so that you can refer to it in column bodies using ${uid}. You can also use uid_rowNum to refer to the current row number. Two tables in the same page can't have the same id (paging and sorting will affect both). If no "htmlId" is specified the same value will be used for the html id of the generated table.

    So, all you need is

     <display:column title="Status">
          <c:if test="${txt.statusType == '1'}">
            Active
          </c:if>
          <c:if test="${txt.statusType == '0'}">
            Passive
          </c:if>
     </display:column>