user1141946 user1141946 - 1 year ago 92
Java Question

ClassCastException when using formatDate

I'm having trouble trying to figure out why my formatDate is not working correctly. Here is my code:


@DateTimeFormat(style = "SS")
private Date myDate;

public Date getMyDate() {
return this.myDate;
public void setMyDate(Date myDate) {
this.myDate = myDate;

JSP - portion of the code that uses the fmt:formatDate code:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="" %>
<%@ taglib prefix="fmt" uri="" %>

<c:forEach var="foo" items="${fooList}" varStatus="i">
<td><fmt:formatDate value="${foo.myDate}" pattern="MM/dd/yyyy"/></td>



Here is a modified version of the controller, all parts dealing with the date are shown here.

@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String list(@PathVariable("id") String id, Model uiModel) {
List<foo> fooList = createList(fooList);

uiModel.addAttribute("fooList", fooList);


When running my application I get this error:

java.lang.ClassCastException:$SpringLocalizationContext incompatible with java.lang.String

***Error only shows when formateDate code is in there, otherwise all EL evaluate fine.

Anyone know why this may be happening?

Answer Source

Found the solution as to why my fmt tag was not working. I needed to change my dependency from:




Thanks for the suggestions!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download