title: Spring Web Flow Conversion Service in JavaConfig
body: <p>I've started working on a web application in Spring Weblow. The idea is to write as much as possible in Java, rather than XML. So I started off with a JavaConfig file for both the MVC configuration and the Web Flow configuration. But I ran into a problem when needing converters for entering and submitting a form with Spring Web Flow.</p>
  
  <p>I did a lot of research on ConversionService and Converters. I found plenty examples of implementing a custom ConversionService and custom Converters, but I found no examples to to add the ConversionService to the Web Flow configuration in JavaConfig (configuration was always XML).</p>
  
  <p>I did try to reproduce the XML config in Java, which nearly worked. In a form page, a list of POJOs (Employee) was represented as a dropdownlist. The input was <code>List&lt;Employee&gt;</code> and the converter (subclass of StringToObject) worked to represent each Employee as a String. But when submitting the form, I got the error that no converter was found for String to Employee. So basically, the custom converter was found and used when rendering the page, but when submitting the form, the same converter could not be found for the reverse process.</p>
  
  <p>I eventually got it fixed by rolling the JavaConfig back to XML config and adding a custom Formatter to the ConversionService of the MVC config. But I'd like to make this work in JavaConfig if it is at all possible.
  I believe the problem is that a ConversionService bean (org.springframework.core.convert package) needs to be added to the MVC config, because this bean needs to be set as a delegate ConversionService in the ConversionService bean to be added to the Web Flow Config (the latter from the org.springframework.binding.convert package). But I don't know how to add this core ConversionService in JavaConfig like in the mvc:annotation-driven tag in the code below.</p>
  
  <p>It all boils down to needing the JavaConfig version of the following code:</p>
  
  <pre><code>&lt;mvc:annotation-driven conversion-service="typeConversionService" ... /&gt;
  
  &lt;bean id="typeConversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"&gt;
       &lt;property name="formatters"&gt;
         &lt;list&gt;
           &lt;bean class="some.package.holidays.formatter.EmployeeFormatter"&gt;
             &lt;constructor-arg ref="employeeService"/&gt;
           &lt;/bean&gt;
           &lt;bean class="org.springframework.format.datetime.DateFormatter"&gt;
              &lt;constructor-arg value="dd/MM/yyyy"/&gt;
           &lt;/bean&gt;
  
         &lt;/list&gt;
       &lt;/property&gt;
     &lt;/bean&gt;
  </code></pre>
  
  <p>If anyone would know about JavaConfig for Spring Webflow, especially about adding a ConversionService, please let me know, it would be a great help.</p>