2015-11-24 1 views
0

Я пытаюсь показать в Spring <form:input> элемент Date, то есть поле POJO, сохраненное на Db.Ошибка при отображении даты (java.sql.Date) в теге весны формы

Это мой 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; 
    .... 
} 

Это моя страница JSP

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

Это ошибка я получаю

 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) 
+0

Да, я использую Spring MVC. Я не поставил код контроллера, потому что я ничего не делаю; Я просто «добавляю» свое pojo к «модели» – MDP

+0

Пожалуйста, проверьте мой ответ. Вы можете голосовать и принимать, если она служит цели! – SyntaX

ответ

2

Из Exception JodaTime library not available - @DateTimeFormat not supported, то ясно, что joda-time jar отсутствует в пути сборки.

Пожалуйста, добавьте Joda-time LIB, чтобы построить путь или в список зависимостей , если вы используете maven.

API doc ясно упоминает, что @DateTimeFormat поддерживает форматирование по шаблону стиля, ISO времени даты шаблон или шаблон строке пользовательского формата. Может применяться к java.util.Date, java.util.Calendar, java.long.Long, Joda-Time типы значений; и по состоянию на Spring 4 и JDK 8, до JSR-310 java.time типов тоже.

Пожалуйста, не используйте @DateTimeFormat с java.sql.Date, так как он не поддерживается.

+1

downvoter комментарии пожалуйста? – soorapadman

+0

Это был не я! : | – MDP

+0

Я добавил joda-tima-2.2.jar и включил java.sql.Date в java.util.Date., Но я продолжаю получать «недоступную библиотеку JodaTime». Мне нужна конкретная версия Joda-time, так как я использую Spring и Hibernate? – MDP

Смежные вопросы