I have been working with webflow quite recently, and I am having problems creating a custom converter for date binding (I need to change the default template for "dd-MM-yyyy")
So I'm trying to do something like this:
<view-state id="viewAnexos" view="myview" model="myModelBean"> <binder> <binding property="anyDateOfTheBean" required="true" converter="customConverter"/> </binder> <transition on="saveAnexo" to="viewAnexos" bind="true"> <evaluate expression="myController.saveAction(myModelBean, messageContext)" /> </transition> </view-state>
And I defined a ConversionService
@Service("conversionService") public class FlowConversionService extends DefaultConversionService { public void FlowConversionService() { addDefaultConverters(); } @Override protected void addDefaultConverters() { super.addDefaultConverters(); addConverter(new StringToDateCustomConverter()); addConverter("customCoverter,"new StringToDateCustomConverter());
And CustomConverter
public class StringToDateCustomConverter extends StringToObject { private DateFormat format = null; public StringToDateCustomConverter() { super(StringToDateCustomConverter.class); format = new SimpleDateFormat("dd/MM/yyyy"); } @Override protected Object toObject(String string, Class targetClass) throws ParseException { return format.parse(string); } @Override protected String toString(Object object) { return format.format((Date) object); }
}
And in my servlet.xml file I defined
<webflow:flow-builder-services id="flowBuilderServices" view-factory-creator="mvcViewFactoryCreator" conversion-service="conversionService"/> <bean id="conversionService" class="es.xunta.emprego.converter.FlowConversionService"/>
And after all this, I will have the following error:
org.springframework.binding.convert.ConversionExecutorNotFoundException: Custom ConversionExecutor with id 'customConverter' cannot convert from sourceClass [java.lang.String] to targetClass [java.util.Date]
Any ideas on what I'm missing here ...? Thanks in advance...
source share