2012-08-03 86 views
1

我在我的struts 2應用程序中使用顯示標籤顯示學生列表(名稱,標記,結果)。顯示標籤內的條件檢查

如果學生得分超過80我需要以綠色顯示整行否則我需要以紅色顯示它 。以下是我的場景,我不熟悉顯示標記,請幫我解決這個問題問題。

<display:table name="studentList" id = "student" cellspacing="1px" class="center"> 

<display:caption class="caption"><b>Student Mark List</b></display:caption> 

if(mark>=80) 
{ 
<display:column title="Student Name" property="name" class="green"> </display:column> 
<display:column title="Student Mark" property="mark" class="green"></display:column> 
<display:column title="Student Result" property="result" class="green"> </display:column> 
} 
else 
{ 
<display:column title="Student Name" property="name" class="red"> </display:column> 
<display:column title="Student Mark" property="mark" class="red"></display:column> 
<display:column title="Student Result" property="result" class="red"> </display:column> 
} 

在此先感謝。

回答

2

我加入這個標籤庫在我的jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 

的開始,我加入以下代碼

<display:table name="studentList" id = "student" cellspacing="1px" class="center"> 

<display:caption class="caption"><b>Student Mark List</b></display:caption> 

<c:choose> 
      <c:when test="${mark>='80'}"> 
       <c:set var="css" value="tableColumnGreen"/> 
      </c:when>            

      <c:otherwise> 
       <c:set var="css" value="tableColumnRed"/> 
      </c:otherwise> 
</c:choose> 
<display:column title="Student Name" property="name" class="${css}"> </display:column> 
<display:column title="Student Mark" property="mark" class="${css}"></display:column> 
<display:column title="Student Result" property="result" class="${css}"> </display:column> 

這有助於me.Thanks給大家。

+0

我想知道如何在標籤上應用樣式,而不是在每個​​標籤上應用樣式,但此解決方案讓我再次移動,並且我很感激它。 – 2013-10-23 15:59:10

+0

@ k-den,非常感謝。 – Mohan 2013-11-04 15:48:09