Bom Dia Senhores… estou fazendo uma pequena aplicação utilizando SpringMVC e o Oracle, nesta aplicação eu criei uma Classe Processo, onde nesta classe existem dois atributos, os quais são:
private Calendar dataAbertura;
private Calendar dataFechamento;
Ocorre que o Spring (me parece) não consegue converter em Date, esperando assim uma String para popular o objeto e persistir no Oracle… segue o Erro:
Grave: Servlet.service() for servlet [springMVC] in context with path [/projeto-am-sysJur-springMVC] threw exception [Request processing failed; nested exception is org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'processo' on field 'dataAbertura': rejected value [01/02/2013]; codes [typeMismatch.processo.dataAbertura,typeMismatch.dataAbertura,typeMismatch.java.util.Calendar,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [processo.dataAbertura,dataAbertura]; arguments []; default message [dataAbertura]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Calendar' for property 'dataAbertura'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Calendar] for property 'dataAbertura': no matching editors or conversion strategy found]] with root cause
org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'processo' on field 'dataAbertura': rejected value [01/02/2013]; codes [typeMismatch.processo.dataAbertura,typeMismatch.dataAbertura,typeMismatch.java.util.Calendar,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [processo.dataAbertura,dataAbertura]; arguments []; default message [dataAbertura]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Calendar' for property 'dataAbertura'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Calendar] for property 'dataAbertura': no matching editors or conversion strategy found]
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doBind(HandlerMethodInvoker.java:810)
Fiz um teste mudando estes dois atributos, ou seja mudei de Calendar para String e onde estava assim:
private Calendar dataAbertura;
private Calendar dataFechamento;
ficou assim:
private String dataAbertura;
private String dataFechamento;
Mas confesso que, pra mim, é meio indigesto trabalhar com datas utilizando o tipo primitivo String! (rs) - Se alguém já passou por isso e puder ajudar… agradeço desde já!
Abraços e Feliz 2013!