Reputation: 2826
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.
Upvotes: 1
Views: 337
Reputation: 4129
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>
Upvotes: 1