Formatting a GregorianCalendar in EL with JSTL / fmt

I have a little problem with the JSP page. I use Stripes as a framework, but this should not be relevant. Basically, I have a bean that returns a date in the form of a GregorianCalendar via getter. I have to show this date in JSP. When I try:

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

I get an exception saying that it cannot convert GregorianCalendar to Date .

I understand that fmt:formatDate formats a Date object, not a GregorianCalendar , but is there a way to wrap it? Since this is a destination, and I have a pre-encoded bean, I am not allowed to touch the bean, so I cannot convert its getter to date to return Date .

How can I solve this problem better?

+4
source share
1 answer

It really only supports java.util.Date . You need to call Calendar#getTime() to find out the calendar.

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

Source: https://habr.com/ru/post/1347311/


All Articles