Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting GregorianCalendar in EL with JSTL/fmt

I'm having a small problem with a JSP page. I'm using Stripes as framework but this should not be that relevant. Basically I have a bean that returns via a getter a date in the form of a GregorianCalendar. I have to display this date in JSP. When I try:

<fmt:formatDate type="both" dateStyle="full" value="${myObject.itsGregorian}">

I get an exception saying that he is unable to convert GregorianCalendar to Date.

I understand that fmt:formatDate formats a Date object and not a GregorianCalendar, but is there a way to turn around it? Since this is an assignment and I've got a pre-coded Bean I'm not allowed to touch the bean, so I can't transform its getter for the date to return a Date.

How can I solve this the best?

like image 772
JBoy Avatar asked Apr 08 '11 21:04

JBoy


1 Answers

It indeed only supports java.util.Date. You need to call Calendar#getTime() to get it out the calendar.

<fmt:formatDate type="both" dateStyle="full" value="${myObject.itsGregorian.time}">
like image 81
BalusC Avatar answered Oct 18 '22 07:10

BalusC