JBoy
JBoy

Reputation: 5745

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?

Upvotes: 6

Views: 8097

Answers (1)

BalusC
BalusC

Reputation: 1108912

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

Upvotes: 10

Related Questions