当前位置: 动力学知识库 > 问答 > 编程问答 >

spring - No custom ConversionExecutor found with id 'shortDate'

问题描述:

I have defined a custom converter for converting a date String to a java.sql.Date object when transiting state in a java spring webflow. However I am getting the error below when submitting the form.

Can you help me understand why am I getting this error?

I am using 4.1.5.RELEASE spring framework 2.4.2.RELEASE spring webflow.

Converter:

import org.springframework.binding.convert.converters.StringToObject;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.text.ParseException;

import java.sql.Date;

public class StringToDateTwoWayConverter extends StringToObject {

private DateFormat formatter = null;

public StringToDateTwoWayConverter () {

super(StringToDateTwoWayConverter.class);

formatter = new SimpleDateFormat("dd/MM/yyyy");

}

@Override

protected Object toObject(String string, Class targetClass) throws Exception {

Date date = null;

try {

long parsedDate = formatter.parse(string).getTime();

date = new Date(parsedDate);

} catch (ParseException e) {

e.printStackTrace();

return null;

}

return date;

}

@Override

protected String toString(Object object) throws Exception {

Date date = (Date) object;

return formatter.format(date);

}

}

conversionService:

import com.housemanagement.converter.StringToDateTwoWayConverter;

import org.springframework.binding.convert.service.DefaultConversionService;

import org.springframework.stereotype.Component;

@Component("conversionService")

public class ApplicationConversionService extends DefaultConversionService

{

@Override

protected void addDefaultConverters() {

super.addDefaultConverters();

this.addConverter(new StringToDateTwoWayConverter());

this.addConverter("shortDate", new StringToDateTwoWayConverter());

}

}

webflow-config.xml

<flow:flow-builder-services id="flowBuilderServices" view-factory-creator="mvcViewFactoryCreator" conversion-service="conversionService" />

Form binding

<binding property="dob" converter="shortDate" required="true" />

Stacktrace:

Warning: StandardWrapperValve[dispatcher]: Servlet.service() for servlet dispatcher threw exception

org.springframework.binding.convert.ConversionExecutorNotFoundException: No custom ConversionExecutor found with id 'shortDate' for converting from sourceClass [java.lang.String] to targetClass [java.sql.Date]

at org.springframework.binding.convert.service.GenericConversionService.getConversionExecutor(GenericConversionService.java:181)

at org.springframework.webflow.engine.builder.support.FlowBuilderContextImpl$ParentConversionServiceProxy.getConversionExecutor(FlowBuilderContextImpl.java:159)

at org.springframework.binding.convert.service.GenericConversionService.getConversionExecutor(GenericConversionService.java:179)

at org.springframework.webflow.mvc.view.AbstractMvcView.addMapping(AbstractMvcView.java:444)

at org.springframework.webflow.mvc.view.AbstractMvcView.addModelBindings(AbstractMvcView.java:409)

at org.springframework.webflow.mvc.view.AbstractMvcView.bind(AbstractMvcView.java:387)

at org.springframework.webflow.mvc.view.AbstractMvcView.processUserEvent(AbstractMvcView.java:225)

at org.springframework.webflow.engine.ViewState.handleEvent(ViewState.java:225)

at org.springframework.webflow.engine.ViewState.resume(ViewState.java:195)

at org.springframework.webflow.engine.Flow.resume(Flow.java:537)

at org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:259)

at org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:169)

at org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:228)

at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)

at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)

at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)

at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)

at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)

at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)

at org.glassfish.tyrus.servlet.TyrusServletFilter.doFilter(TyrusServletFilter.java:295)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)

at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)

at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)

at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)

at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)

at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)

at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)

at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)

at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)

at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)

at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)

at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)

at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)

at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)

at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)

at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)

at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)

at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)

at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)

at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)

at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)

at java.lang.Thread.run(Thread.java:745)

网友答案:

you need to call super with the type you want to register:

public StringToDateTwoWayConverter () {
    super(Date.class);
    formatter = new SimpleDateFormat("dd/MM/yyyy");
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: