0

I wish to check and highlight if the date is going to expire in 1 week or 1 month... using jstl in jsp. Date between today and + 1week

Date value in session attribute : '09-03-2020'

<fmt:formatDate value="${coMaster.payDate}" pattern="dd-mm-yyyy" var="payDate" />
<c:choose>
    <c:when test="${payDate ge thisweek}">
       <c:set var="coStyle" value="red"/>
    </c:when>

    <c:otherwise>
       <c:set var="coStyle" value="green"/>
   </c:otherwise>
</c:choose>

<display:column title="Pay Date" property="payDate"  sortable="true" class="${coStyle}" />    
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
uday
  • 181
  • 2
  • 16
  • very simple, i want to change the data table cell value background color. if the date is going to expire in 1 week. – uday Mar 04 '20 at 10:18

1 Answers1

0

You didn't provide code showing what the type of thisweek is. Make sure you are using Date objects for both dates. So, don't use fmt:formatDate, because that will get you a String which you cannot use for date comparison.

Also, your c:choose block setting a variable will work, but is somewhat overkill if you compare it with ternary expression:

class="${coMaster.payDate ge thisweek ? 'red' : 'green'}"

See also:

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102