1

Is it possible to to check / compare the value of a Date object in JSP, using EL only? I'm making a web application using Spring MVC + JSP and I'm passing an object of Date class to JSP in the controller using

model.addAttribute("date", randomDate);

In JSP I would like to check, if the date has a certain value. Specifically I would need to check for a certain year, month and day, in the spirit of

<c:if test="${date == '1.1.2014'}">
    <span>Happy new Year!</span>
</c:if>

Is there a straightforward way to inspect the value of Data type variable using EL, or JSTL function? I would like to avoid scriptlets, if possible.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Warlord
  • 2,798
  • 16
  • 21
  • 2
    Why don't you do the check in the controller? – Sotirios Delimanolis Mar 05 '14 at 17:06
  • @SotiriosDelimanolis I am currently doing it that way, but it's not very nice, as it only determines the styling of the element, so I was wondering if there is a way of doing it directly in JSP. – Warlord Mar 05 '14 at 17:15
  • possible duplicate of [Is it possible to create a date value in Expression Language?](http://stackoverflow.com/questions/4512682/is-it-possible-to-create-a-date-value-in-expression-language). Create the desired date in page context, then compare it with your date object from server. – Luiggi Mendoza Mar 05 '14 at 17:24

1 Answers1

1

Try this :

<fmt:formatDate pattern="MM-dd-yyyy" value="${date}" var="formatedDate" />
<c:if test="${formatedDate == '01-01-2014'}">
    <span>Happy new Year!</span>
</c:if>
Rida BENHAMMANE
  • 4,111
  • 1
  • 14
  • 25