Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

rejected value [10/10/2010]; codes [typeMismatch.produto.dataLancamento,

Adicionei o campo, entretanto está dando erro rejected value [10/10/2010]; codes [typeMismatch.produto.dataLancamento. Para gravar e a mostrar a lista fis diferente da aula, mas estava funcionando corretamente, depois da data está dando erro.

Segue o erro

Type Exception Report

Message Request processing failed; nested exception is org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'produto' on field 'dataLancamento': rejected value [10/10/2010]; codes [typeMismatch.produto.dataLancamento,typeMismatch.dataLancamento,typeMismatch.java.sql.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [produto.dataLancamento,dataLancamento]; arguments []; default message [dataLancamento]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.sql.Date' for property 'dataLancamento'; nested exception is java.lang.IllegalArgumentException: Could not parse date: Unparseable date: "10/10/2010"]
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause

org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'produto' on field 'dataLancamento': rejected value [10/10/2010]; codes [typeMismatch.produto.dataLancamento,typeMismatch.dataLancamento,typeMismatch.java.sql.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [produto.dataLancamento,dataLancamento]; arguments []; default message [dataLancamento]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.sql.Date' for property 'dataLancamento'; nested exception is java.lang.IllegalArgumentException: Could not parse date: Unparseable date: "10/10/2010"]
    org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:111)
    org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:75)
    org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:156)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:117)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Note A pilha de erros completa da causa principal está disponível nos logs do servidor.

Apache Tomcat/9.0.29

Algumas classes estão neste link https://gist.github.com/alinelsilva/fd6c828672084f859373b1e6fe39c118.js

2 respostas

Oi Aline,

Você está formatando a data conforme uma das opções abaixo?

@Entity
public class Produto {
    [...]
    @DateTimeFormat(pattern="dd/MM/yyyy")
    private Calendar dataLancamento;
    [...]
}
@Bean
public FormattingConversionService mvcConversionService(){
    DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
    DateFormatterRegistrar formatterRegistrar = new DateFormatterRegistrar();
    formatterRegistrar.setFormatter(new DateFormatter("dd/MM/yyyy"));
    formatterRegistrar.registerFormatters(conversionService);

    return conversionService;
}
solução!

Oi Otávio usando a primeira opção deu certo. Muito obrigada!