0

I'm trying to show in a Spring <form:input> element a Date, that is a field of a POJO saved on the Db.

This is my POJO

import java.sql.Date;
import org.springframework.format.annotation.DateTimeFormat;

@Component
@MappedSuperclass
public class Persona implements Serializable{           
    ....
    @Column(name="data_di_nascita", nullable=false, updatable=true)
    @DateTimeFormat(pattern="yyyy/MM/dd")
    private Date dataDiNascita;
    ....
}

This is my jsp page

<form:form modelAttribute="persona">
...
   Data di nascista<form:input path="dataDiNascita"/><br/>
...
</form:form> 

This is the error I get

      org.springframework.core.convert.ConversionFailedException: Failed to convert from type @javax.persistence.Column @org.springframework.format.annotation.DateTimeFormat java.sql.Date to type java.lang.String for value '1978-07-01'; nested exception is java.lang.IllegalStateException: JodaTime library not available - @DateTimeFormat not supported
        org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:41)
        org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:171)
        org.springframework.validation.AbstractPropertyBindingResult.formatFieldValue(AbstractPropertyBindingResult.java:125)
        org.springframework.validation.AbstractBindingResult.getFieldValue(AbstractBindingResult.java:222)
        org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:120)
        org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:178)
        org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:198)
        org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:164)
        org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:151)
        org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:142)
        org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:126)
        org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:421)
        org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:142)
        org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
        org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
        org.apache.jsp.WEB_002dINF.views.persona_jsp._jspx_meth_form_005finput_005f5(persona_jsp.java:317)
        org.apache.jsp.WEB_002dINF.views.persona_jsp._jspx_meth_form_005fform_005f0(persona_jsp.java:135)
        org.apache.jsp.WEB_002dINF.views.persona_jsp._jspService(persona_jsp.java:76)
        org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
        org.apache.jasper.runtime.PageContextImpl.doInclude(PageContextImpl.java:688)
        org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:682)
        org.apache.tiles.jsp.context.JspTilesRequestContext.include(JspTilesRequestContext.java:103)
        org.apache.tiles.jsp.context.JspTilesRequestContext.dispatch(JspTilesRequestContext.java:96)
        org.apache.tiles.renderer.impl.UntypedAttributeRenderer.write(UntypedAttributeRenderer.java:61)
        org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:103)
        org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:669)
        org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:337)
        org.apache.tiles.jsp.taglib.InsertAttributeTag.render(InsertAttributeTag.java:234)
        org.apache.tiles.jsp.taglib.InsertAttributeTag.render(InsertAttributeTag.java:211)
        org.apache.tiles.jsp.taglib.RenderTag.doEndTag(RenderTag.java:220)
        org.apache.jsp.WEB_002dINF.template.default_.template1_jsp._jspx_meth_tiles_005finsertAttribute_005f2(template1_jsp.java:284)
        org.apache.jsp.WEB_002dINF.template.default_.template1_jsp._jspService(template1_jsp.java:115)
        org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        org.apache.tiles.servlet.context.ServletTilesRequestContext.forward(ServletTilesRequestContext.java:241)
        org.apache.tiles.servlet.context.ServletTilesRequestContext.dispatch(ServletTilesRequestContext.java:222)
        org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)
        org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:103)
        org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:669)
        org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:689)
        org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:643)
        org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:626)
        org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:322)
        org.springframework.web.servlet.view.tiles2.TilesView.renderMergedOutputModel(TilesView.java:124)
        org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
        org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180)
        org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
        org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
        org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
        org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
        org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
        org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:125)
        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
        org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
        org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
        org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)



    root cause 
    java.lang.IllegalStateException: JodaTime library not available - @DateTimeFormat not supported
        org.springframework.format.support.DefaultFormattingConversionService$NoJodaDateTimeFormatAnnotationFormatterFactory.getPrinter(DefaultFormattingConversionService.java:127)
        org.springframework.format.support.DefaultFormattingConversionService$NoJodaDateTimeFormatAnnotationFormatterFactory.getPrinter(DefaultFormattingConversionService.java:1)
        org.springframework.format.support.FormattingConversionService$AnnotationPrinterConverter.convert(FormattingConversionService.java:221)
        org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:35)
        org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:171)
        org.springframework.validation.AbstractPropertyBindingResult.formatFieldValue(AbstractPropertyBindingResult.java:125)
        org.springframework.validation.AbstractBindingResult.getFieldValue(AbstractBindingResult.java:222)
        org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:120)
        org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:178)
        org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:198)
        org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:164)
        org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:151)
        org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:142)
        org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:126)
        org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:421)
        org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:142)
        org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
        org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
        org.apache.jsp.WEB_002dINF.views.persona_jsp._jspx_meth_form_005finput_005f5(persona_jsp.java:317)
        org.apache.jsp.WEB_002dINF.views.persona_jsp._jspx_meth_form_005fform_005f0(persona_jsp.java:135)
        org.apache.jsp.WEB_002dINF.views.persona_jsp._jspService(persona_jsp.java:76)
        org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
        org.apache.jasper.runtime.PageContextImpl.doInclude(PageContextImpl.java:688)
        org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:682)
        org.apache.tiles.jsp.context.JspTilesRequestContext.include(JspTilesRequestContext.java:103)
        org.apache.tiles.jsp.context.JspTilesRequestContext.dispatch(JspTilesRequestContext.java:96)
        org.apache.tiles.renderer.impl.UntypedAttributeRenderer.write(UntypedAttributeRenderer.java:61)
        org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:103)
        org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:669)
        org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:337)
        org.apache.tiles.jsp.taglib.InsertAttributeTag.render(InsertAttributeTag.java:234)
        org.apache.tiles.jsp.taglib.InsertAttributeTag.render(InsertAttributeTag.java:211)
        org.apache.tiles.jsp.taglib.RenderTag.doEndTag(RenderTag.java:220)
        org.apache.jsp.WEB_002dINF.template.default_.template1_jsp._jspx_meth_tiles_005finsertAttribute_005f2(template1_jsp.java:284)
        org.apache.jsp.WEB_002dINF.template.default_.template1_jsp._jspService(template1_jsp.java:115)
        org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        org.apache.tiles.servlet.context.ServletTilesRequestContext.forward(ServletTilesRequestContext.java:241)
        org.apache.tiles.servlet.context.ServletTilesRequestContext.dispatch(ServletTilesRequestContext.java:222)
        org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)
        org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:103)
        org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:669)
        org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:689)
        org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:643)
        org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:626)
        org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:322)
        org.springframework.web.servlet.view.tiles2.TilesView.renderMergedOutputModel(TilesView.java:124)
        org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
        org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180)
        org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
        org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
        org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
        org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
        org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
        org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:125)
        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
        org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)


org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
2
  • Yes, I'm using Spring MVC. I didn't put the code of the controller because there I don't do anything; I just "add" my pojo to the "model" Commented Nov 24, 2015 at 9:24
  • Please check out my answer. You may up vote and accept if it serves the purpose! Commented Nov 24, 2015 at 9:42

1 Answer 1

3

From the Exception JodaTime library not available - @DateTimeFormat not supported, it is clear that the joda-time jar is missing in the build path.

Please add the Joda-time lib to build path or to your dependency list if you are using maven.

The API doc clearly mentions that @DateTimeFormat supports formatting by style pattern, ISO date time pattern, or custom format pattern string. Can be applied to java.util.Date, java.util.Calendar, java.long.Long, Joda-Time value types; and as of Spring 4 and JDK 8, to JSR-310 java.time types too.

Please do not use @DateTimeFormat with java.sql.Date since it is not supported.

Sign up to request clarification or add additional context in comments.

5 Comments

I added joda-tima-2.2.jar and turned java.sql.Date into java.util.Date.,but I keep on getting "JodaTime library not available". Do I need a specific versione of Joda-time since I'm using Spring and Hibernate?
Which version of Spring you are using?
Spring version is 3.1.4
You know what? If I put Joda-time library in my application LIB folder, I get the error. If i put the library inside Apache lib folder it works... Why?
The jars which are present in the WebContent\ WEB-INF\lib are used during the runtime in a dynamic web project. You can google out to find the way to customize this. But in maven you can configure this easily.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.