Spring web stream date binding

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"/> <!-- the type is java.util.Date --> </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()); //This method is deprecated, so how should I do it? } } 

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...

+4
source share
1 answer

I just launched a few things and now it works.

1.-Renamed StringToDateCustomConverter to StringToDate.

2. - ConversionService has this way

 @Service("conversionService") public class FlowConversionService extends DefaultConversionService { @Override protected void addDefaultConverters() { super.addDefaultConverters(); addConverter(new StringToDate()); //This is overrided } } 

3.-Binding in flow.xml is no longer required, so ...

  <view-state id="viewAnexos" view="myview" model="myModelBean"> <transition on="saveAnexo" to="viewAnexos" bind="true"> <evaluate expression="myController.saveAction(myModelBean, messageContext)" /> </transition> </view-state> 

And what is he, it works great !!

+1
source

Source: https://habr.com/ru/post/1498374/


All Articles