J'éprouve des difficultés en ce qui concerne la validation de date dans Spring MVC 3erreur invalide Format de date Spring MVC message ne montrant
ClientForm.java
public class ClientForm
{
private Date bday = new Date();
//Getters and setters
}
Dans mon contrôleur
@RequestMapping(value = "/save", method = RequestMethod.POST)
public String save(@Valid ClientForm form, BindingResult result)
{
if(result.hasErrors())
{
return "client.form";
}
return "redirect:search";
}
messages. propriétés
client.search.notnumber=Search value must be a number
typeMismatch.java.util.Date = Invalid date
jsp
<form:form action="save.html" method="post" commandName="clientForm">
<form:input path="bday" cssClass="date-pick dp-applied" />
<form:errors path="bday" element="label" cssClass="error"/>
</form:form>
Autres messages de validation dans '' messages.properties fonctionne très bien mais quand je tapais intentionnellement une date non valide (à savoir 111/12/2011)
je reçu ce message d'erreur
org.springframework.web.util.NestedServletException: traitement Échec de la demande; l'exception imbriquée est org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 erreurs Erreur de zone dans l'objet 'clientForm' dans le champ 'bday': valeur rejetée [21/05e/2011]; codes [typeMismatch.clientForm.bday, typeMismatch.bday, typeMismatch.java.util.Date, typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [clientForm.bday, bday]; arguments []; message par défaut [bday]]; default message [Échec de la conversion de la valeur de propriété de type 'java.lang.String' en type requis 'java.util.Date' pour la propriété 'bday'; l'exception imbriquée est org.springframework.core.convert.ConversionFailedException: Impossible de convertir la valeur "21/05e/2011" du type "java.lang.String" en type "java.util.Date"; l'exception imbriquée est java.lang.IllegalArgumentException: format non valide: "21/05e/2011" est incorrect à "e/2011"] org.springframework.web.servlet.FrameworkServlet.processRequest (FrameworkServlet.java:656) org. springframework.web.servlet.FrameworkServlet.doPost (FrameworkServlet.java:560) javax.servlet.http.HttpServlet.service (HttpServlet.java:637) javax.servlet.http.HttpServlet.service (HttpServlet.java:717) org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain (AbstractShiroFilter.java:359) org.apache.shiro.web.servlet.AbstractShiroFilter $ 1.call (AbstractShiroFilter.java:275) org.apache.shiro. subject.support.SubjectCallable.doCall (SubjectCallable.java:90) org.apache.shiro.subject.support.SubjectCallable.call (SubjectCallable .java: 83) org.apache.shiro.subject.support.DelegatingSubject.execute (DelegatingSubject.java:344) org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal (AbstractShiroFilter.java:272) org. apache.shiro.web.servlet.OncePerRequestFilter.doFilter (OncePerRequestFilter.java:81) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate (DelegatingFilterProxy.java:237) org.springframework.web.filter.DelegatingFilterProxy.doFilter (DelegatingFilterProxy.java:167) cause initiale org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 erreurs Erreur de zone dans l'objet 'clientForm' dans le champ 'bday': valeur rejetée [21/05f/2011 ] codes [typeMismatch.clientForm.bday, typeMismatch.bday, typeMismatch.java.util.Date, typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [clientForm.bday, bday]; arguments []; message par défaut [bday]]; default message [Impossible de convertir la valeur de la propriété de type 'java.lang.String 'au type requis' java.util.Date 'pour la propriété' bday '; l'exception imbriquée est org.springframework.core.convert.ConversionFailedException: Impossible de convertir la valeur "21/05e/2011" du type "java.lang.String" en type "java.util.Date"; l'exception imbriquée est java.lang.IllegalArgumentException: format non valide: "21/05e/2011" est incorrect à "e/2011"] org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doBind (HandlerMethodInvoker.java:810) org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments (HandlerMethodInvoker.java:359) org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod (HandlerMethodInvoker.java:153) org . springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod (AnnotationMethodHandlerAdapter.java:426) org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle (AnnotationMethodHandlerAdapter.java:414) org.springframework.web. servlet.DispatcherServlet.doDispatch (DispatcherSer vlet.java:790) org.springframework.web.servlet.DispatcherServlet.doService (DispatcherServlet.java:719) org.springframework.web.servlet.FrameworkServlet.processRequest (FrameworkServlet.java:644) org.springframework.web .servlet.FrameworkServlet.doPost (FrameworkServlet.java:560) javax.servlet.http.HttpServlet.service (HttpServlet.java:637) javax.servlet.http.HttpServlet.service (HttpServlet.java:717) org . apache.shiro.web.servlet.AbstractShiroFilter.executeChain (AbstractShiroFilter.java:359) org.apache.shiro.web.servlet.AbstractShiroFilter $ 1.call (AbstractShiroFilter.java:275) org.apache.shiro.subject.support .SubjectCallable.doCall (SubjectCallable.java:90) org.apache.shiro.subject.support.SubjectCalla ble.call (SubjectCallable.java:83) org.apache.shiro.subject.support.DelegatingSubject.execute (DelegatingSubject.java:344) org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal (AbstractShiroFilter.java: 272) org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter (OncePerRequestFilter.java:81) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate (DelegatingFilterProxy.java:237) org.springframework.web.filter .DelegatingFilterProxy.doFilter (DelegatingFilterProxy.java:167)
J'ai volontairement mis ce 'e' dans la date, j'essayais de faire ressortir mon message d'erreur dans les validations de date – Kevin