views:

21

answers:

1

...but registered

Using Spring 3

I have two converters registered as follows:

<beans:bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
   <beans:property name="converters">
      <beans:list>
      <beans:bean class="mypackage.CalendarToStringConverter" />
      <beans:bean class="mypackage.StringToCalendarConverter" />
   </beans:list>
   </beans:property>
</beans:bean>

The converters look like this:

public class StringToCalendarConverter implements Converter< String, Calendar > {
   public Calendar convert( String value ) {
      return Calendar.getInstance();
   }
}

public class CalendarToStringConverter implements Converter< Calendar, String > {
   public String convert( Calendar arg0 ) {
      return "23.10.1985";
   }
}

The problem is that they are not used during conversion in post and get requests. What am I doing wrong? What do I havt to do to get this working? THX!

A: 

Here's the converters configuration that works for me. The differences you might try changing:

  • I pass in a set instead of a list. (setConverters takes a Set parameter)
  • I use FormattingConversionServiceFactoryBean instead of ConversionServiceFactoryBean. (Should not matter)
  • My converters are defined as top level beans and referenced. (Also should not matter)

Hopefully one of this will fix your problem.

<util:set id="converters" >
   <ref bean="userDao" />
   <ref bean="orderDao" />
<util:set>

<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
    <property name="converters" ref="converters"/>
</bean>
ebelisle