如何使用 jstl 向 displaytag table 添加条件

How to add a condition to displaytag table with jstl

我想生成一个带有显示标签的 table。其中一列是状态类型。并且,此状态类型可以是 1 或 0。(主动或被动)。 Table 是:

<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" 标签是 JSTL。但是,statusType 总是以 "NULL" 的形式出现。我正在尝试很多方法。 如何正确查看这个参数?

table 标签的文档说:

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.

所以,你只需要

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

你可以这样处理:

  <c:if test="${empty statusType}">
    Others
  </c:if>