Custom date type conversions are reported

Source: Internet
Author: User

To learn the custom type converter value, when the type of input and the custom type inconsistency are reported

Convertfromstring....java.text.parseexception:format.parseobject (String) Failedat Java.text.Format.parseObject ( format.java:245) at com.baidu.action.conversion.DateConverter.convertFromString (dateconverter.java:44) at Org.apache.struts2.util.StrutsTypeConverter.convertValue (strutstypeconverter.java:52) at Com.opensymphony.xwork2.conversion.impl.DefaultTypeConverter.convertValue (defaulttypeconverter.java:92) at Com.opensymphony.xwork2.conversion.impl.XWorkConverter.convertValue (xworkconverter.java:314) at Com.opensymphony.xwork2.ognl.OgnlTypeConverterWrapper.convertValue (ognltypeconverterwrapper.java:39) at OGNL. Ognlruntime.getconvertedtype (ognlruntime.java:1081) at OGNL. Ognlruntime.getconvertedtypes (ognlruntime.java:1098) at OGNL. Ognlruntime.getconvertedmethodandargs (ognlruntime.java:1124) at OGNL. Ognlruntime.getappropriatemethod (ognlruntime.java:1210) at OGNL. Ognlruntime.callappropriatemethod (ognlruntime.java:1224) at OGNL. Ognlruntime.setmethodvalue (ognlruntime.java:1503) at OGNL. ObjectpropertyacCessor.setpossibleproperty (objectpropertyaccessor.java:85) at OGNL. Objectpropertyaccessor.setproperty (objectpropertyaccessor.java:162) at Com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.setProperty (objectaccessor.java:27) at OGNL. Ognlruntime.setproperty (ognlruntime.java:2432) at Com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.setProperty (compoundrootaccessor.java:81) at OGNL. Ognlruntime.setproperty (ognlruntime.java:2432) at OGNL. Astproperty.setvaluebody (astproperty.java:127) at OGNL. Simplenode.evaluatesetvaluebody (simplenode.java:220) at OGNL. Simplenode.setvalue (simplenode.java:301) at OGNL. Ognl.setvalue (ognl.java:737) at Com.opensymphony.xwork2.ognl.ognlutil$1.execute (ognlutil.java:293) at Com.opensymphony.xwork2.ognl.ognlutil$1.execute (ognlutil.java:288) at Com.opensymphony.xwork2.ognl.OgnlUtil.compileAndExecute (ognlutil.java:346) at Com.opensymphony.xwork2.ognl.OgnlUtil.setValue (ognlutil.java:288) at Com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue (ognlvaluestack.java:183) AT Com.opensymphony.xwork2.ognl.OgnlValueStack.setValue (ognlvaluestack.java:170) at Com.opensymphony.xwork2.ognl.OgnlValueStack.setParameter (ognlvaluestack.java:152) at Com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters (parametersinterceptor.java:303) at Com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept (parametersinterceptor.java:221) at Com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept (methodfilterinterceptor.java:98) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:245) at Com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept (parametersinterceptor.java:229) at Com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept (methodfilterinterceptor.java:98) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:245) at Com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept (staticparametersinterceptor.java:191 ) at Com.opensymphoNy.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:245) at Org.apache.struts2.interceptor.FileUploadInterceptor.intercept (fileuploadinterceptor.java:253) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:245) at Com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept (modeldriveninterceptor.java:100) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:245) at Com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept (chaininginterceptor.java:145) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:245) at Com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept (prepareinterceptor.java:171) at Com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept (methodfilterinterceptor.java:98) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:245) at Org.apache.struts2.interceptor.servletconfiginterceptor.iNtercept (servletconfiginterceptor.java:164) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke ( defaultactioninvocation.java:245) at Com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept ( parametersinterceptor.java:229) at Com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept ( methodfilterinterceptor.java:98) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke ( defaultactioninvocation.java:245) at Org.apache.struts2.interceptor.MultiselectInterceptor.intercept ( multiselectinterceptor.java:73) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke ( defaultactioninvocation.java:245) at Org.apache.struts2.interceptor.DateTextFieldInterceptor.intercept ( datetextfieldinterceptor.java:125) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke ( defaultactioninvocation.java:245) at Org.apache.struts2.interceptor.CheckboxInterceptor.intercept ( checkboxinterceptor.java:91) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke ( defaultactioninvocation.java:245)At Com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept (i18ninterceptor.java:140) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:245) at Com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept (aliasinterceptor.java:193) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:245) at Com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept (exceptionmappinginterceptor.java:189 ) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:245) at Org.apache.struts2.impl.StrutsActionProxy.execute (strutsactionproxy.java:54) at Org.apache.struts2.dispatcher.Dispatcher.serviceAction (dispatcher.java:567) at Org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction (executeoperations.java:81) at Org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter ( strutsprepareandexecutefilter.java:99) at Org.apache.catalina.core.ApplicationFilterChain.internalDOfilter (applicationfilterchain.java:241) at Org.apache.catalina.core.ApplicationFilterChain.doFilter ( applicationfilterchain.java:208) at Org.apache.catalina.core.StandardWrapperValve.invoke ( standardwrappervalve.java:220) at Org.apache.catalina.core.StandardContextValve.invoke (Standardcontextvalve.java : 122) at Org.apache.catalina.authenticator.AuthenticatorBase.invoke (authenticatorbase.java:505) at Org.apache.catalina.core.StandardHostValve.invoke (standardhostvalve.java:169) at Org.apache.catalina.valves.ErrorReportValve.invoke (errorreportvalve.java:103) at Org.apache.catalina.valves.AccessLogValve.invoke (accesslogvalve.java:956) at Org.apache.catalina.core.StandardEngineValve.invoke (standardenginevalve.java:116) at Org.apache.catalina.connector.CoyoteAdapter.service (coyoteadapter.java:436) at Org.apache.coyote.http11.AbstractHttp11Processor.process (abstracthttp11processor.java:1078) at Org.apache.coyote.abstractprotocol$abstractconnectionhandler.process (abstractprotocol.java:625) at Org.apache.tomCat.util.net.aprendpoint$socketprocessor.dorun (aprendpoint.java:2517) at org.apache.tomcat.util.net.aprendpoint$ Socketprocessor.run (aprendpoint.java:2506) at Java.util.concurrent.ThreadPoolExecutor.runWorker ( threadpoolexecutor.java:1145) at Java.util.concurrent.threadpoolexecutor$worker.run (ThreadPoolExecutor.java:615) At Org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run (taskthread.java:61) at Java.lang.Thread.run ( thread.java:744) did not pass my person [age=5214, Birth=null]

At first I do not understand, why will report this error, where reported this error, not to mention how to solve, this morning, I analyzed, reported this error, that is, this error was caught by the code, not be thrown out, if I now let it be thrown out, at the front desk to " You have entered an incorrect time format. "In the form of display to the user, is it OK?

In the next analysis, then where is the error reported? Since it is a type conversion error, then it should be a custom type converter to report the wrong, again look at the code, in the code

/** * String to date type */@Overridepublic Object convertfromstring (Map context, string[] values, Class toclass) {System.out.pri Ntln ("convertfromstring ..."); if (Toclass = = Date.class) {if (values! = null && values.length > 0) {String value = values[0];try {return GetDateFormat (). Parseobject (value);} catch (ParseException e) {e.printstacktrace ();}}} If no conversion succeeds, return valuesreturn values;}
There is a catch above the error that could have been caught by it,then add the following print code before and after it

catch (ParseException e) {System.out.println ("after Me"); E.printstacktrace (); System.out.println ("Did not pass Me");}


After the experiment, I found the same as I expected!

Java.text.ParseException:Format.parseObject (String) failedconvertfromstring .... After my at Java.text.Format.parseObject (format.java:245) at Com.baidu.action.conversion.DateConverter.convertFromString (dateconverter.java:45) at Org.apache.struts2.util.StrutsTypeConverter.convertValue (strutstypeconverter.java:52) at Com.opensymphony.xwork2.conversion.impl.DefaultTypeConverter.convertValue (defaulttypeconverter.java:92) at Com.opensymphony.xwork2.conversion.impl.XWorkConverter.convertValue (xworkconverter.java:314) at Com.opensymphony.xwork2.ognl.OgnlTypeConverterWrapper.convertValue (ognltypeconverterwrapper.java:39) at OGNL. Ognlruntime.getconvertedtype (ognlruntime.java:1081) at OGNL. Ognlruntime.getconvertedtypes (ognlruntime.java:1098) at OGNL. Ognlruntime.getconvertedmethodandargs (ognlruntime.java:1124) at OGNL. Ognlruntime.getappropriatemethod (ognlruntime.java:1210) at OGNL. Ognlruntime.callappropriatemethod (ognlruntime.java:1224) at OGNL. Ognlruntime.setmethodvalue (ognlruntime.java:1503) at OGNL. ObjectproperTyaccessor.setpossibleproperty (objectpropertyaccessor.java:85) at OGNL. Objectpropertyaccessor.setproperty (objectpropertyaccessor.java:162) at Com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.setProperty (objectaccessor.java:27) at OGNL. Ognlruntime.setproperty (ognlruntime.java:2432) at Com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.setProperty (compoundrootaccessor.java:81) at OGNL. Ognlruntime.setproperty (ognlruntime.java:2432) at OGNL. Astproperty.setvaluebody (astproperty.java:127) at OGNL. Simplenode.evaluatesetvaluebody (simplenode.java:220) at OGNL. Simplenode.setvalue (simplenode.java:301) at OGNL. Ognl.setvalue (ognl.java:737) at Com.opensymphony.xwork2.ognl.ognlutil$1.execute (ognlutil.java:293) at Com.opensymphony.xwork2.ognl.ognlutil$1.execute (ognlutil.java:288) at Com.opensymphony.xwork2.ognl.OgnlUtil.compileAndExecute (ognlutil.java:346) at Com.opensymphony.xwork2.ognl.OgnlUtil.setValue (ognlutil.java:288) at Com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue (ognlvaluestack.java:1(ognlvaluestack.java:170) at Com.opensymphony.xwork2.ognl.OgnlValueStack.setValue Com.opensymphony.xwork2.ognl.OgnlValueStack.setParameter (ognlvaluestack.java:152) at Com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters (parametersinterceptor.java:303) at Com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept (parametersinterceptor.java:221) at Com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept (methodfilterinterceptor.java:98) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:245) at Com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept (parametersinterceptor.java:229) at Com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept (methodfilterinterceptor.java:98) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:245) at Com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept (staticparametersinterceptor.java:191 ) at Com.opensyMphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:245) at Org.apache.struts2.interceptor.FileUploadInterceptor.intercept (fileuploadinterceptor.java:253) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:245) at Com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept (modeldriveninterceptor.java:100) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:245) at Com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept (chaininginterceptor.java:145) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:245) at Com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept (prepareinterceptor.java:171) at Com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept (methodfilterinterceptor.java:98) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:245) at Org.apache.struts2.interceptor.ServletConfigInterceptOr.intercept (servletconfiginterceptor.java:164) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke ( defaultactioninvocation.java:245) at Com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept ( parametersinterceptor.java:229) at Com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept ( methodfilterinterceptor.java:98) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke ( defaultactioninvocation.java:245) at Org.apache.struts2.interceptor.MultiselectInterceptor.intercept ( multiselectinterceptor.java:73) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke ( defaultactioninvocation.java:245) at Org.apache.struts2.interceptor.DateTextFieldInterceptor.intercept ( datetextfieldinterceptor.java:125) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke ( defaultactioninvocation.java:245) at Org.apache.struts2.interceptor.CheckboxInterceptor.intercept ( checkboxinterceptor.java:91) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke ( Defaultactioninvocation.java:245) at Com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept (i18ninterceptor.java:140) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:245) at Com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept (aliasinterceptor.java:193) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:245) at Com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept (exceptionmappinginterceptor.java:189 ) at Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:245) at Org.apache.struts2.impl.StrutsActionProxy.execute (strutsactionproxy.java:54) at Org.apache.struts2.dispatcher.Dispatcher.serviceAction (dispatcher.java:567) at Org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction (executeoperations.java:81) at Org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter ( strutsprepareandexecutefilter.java:99) at Org.apache.catalina.core.ApplicationFilterChain.interNaldofilter (applicationfilterchain.java:241) at Org.apache.catalina.core.ApplicationFilterChain.doFilter ( applicationfilterchain.java:208) at Org.apache.catalina.core.StandardWrapperValve.invoke ( standardwrappervalve.java:220) at Org.apache.catalina.core.StandardContextValve.invoke (Standardcontextvalve.java : 122) at Org.apache.catalina.authenticator.AuthenticatorBase.invoke (authenticatorbase.java:505) at Org.apache.catalina.core.StandardHostValve.invoke (standardhostvalve.java:169) at Org.apache.catalina.valves.ErrorReportValve.invoke (errorreportvalve.java:103) at Org.apache.catalina.valves.AccessLogValve.invoke (accesslogvalve.java:956) at Org.apache.catalina.core.StandardEngineValve.invoke (standardenginevalve.java:116) at Org.apache.catalina.connector.CoyoteAdapter.service (coyoteadapter.java:436) at Org.apache.coyote.http11.AbstractHttp11Processor.process (abstracthttp11processor.java:1078) at Org.apache.coyote.abstractprotocol$abstractconnectionhandler.process (abstractprotocol.java:625) at Org.apache. Tomcat.util.net.aprendpoint$socketprocessor.dorun (aprendpoint.java:2517) at Org.apache.tomcat.util.net.aprendpoint$socketprocessor.run (aprendpoint.java:2506) at Java.util.concurrent.ThreadPoolExecutor.runWorker (threadpoolexecutor.java:1145) at Java.util.concurrent.threadpoolexecutor$worker.run (threadpoolexecutor.java:615) at Org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run (taskthread.java:61) at Java.lang.Thread.run ( thread.java:744) did not pass my person [age=5214, Birth=null]
Now that you know it's the wrong one, the following is so easy. It would be nice to have the problem reported!


The modified code is as follows

/** * String to date type * Resolution of the problem: Simply put the catch  in the E.printstacktrace ();  * Replaced with  throw new Typeconversionexception (); *  the problem is solved! */@Overridepublic Object convertfromstring (Map context, string[] values, Class toclass) {System.out.println (" convertfromstring); if (Toclass = = Date.class) {if (values! = null && values.length > 0) {String value = value S[0];try {return GetDateFormat (). Parseobject (value);} catch (ParseException e) {throw new Typeconversionexception ();}}} If no conversion succeeds, return valuesreturn values;}

I am happy!



Custom date type conversions are reported

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.