2

I am displaying a student list(Name ,Mark, Result) using display tag in my struts 2 application.

if student scored more than 80 i need to display the entire row in green color else i need to display it in red color .Below is my scenario , i am not familiar with display tag, please help me to solve this issue.

<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>
}

Thanks in advance.

Mohan
  • 3,893
  • 9
  • 33
  • 42

1 Answers1

3

I added this taglib at the beginning of my jsp

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

and i added below code

<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>

This helped me.Thanks for everyone.

Mohan
  • 3,893
  • 9
  • 33
  • 42
  • I would have liked to find out how to apply the style at the tag instead of at each tag but this solution gets me moving again and I appreciate it. – k-den Oct 23 '13 at 15:59