title: Spring 3.0 MVC binding Enums Case Sensitive
body: <p>If I have a RequestMapping in a Spring controller like so... </p>
  
  <pre><code>@RequestMapping(method = RequestMethod.GET, value = "{product}")
  public ModelAndView getPage(@PathVariable Product product)
  </code></pre>
  
  <p>And Product is an enum. eg. Product.Home</p>
  
  <p>When I request the page, mysite.com/home</p>
  
  <p>I get</p>
  
  <pre><code>Unable to convert value "home" from type 'java.lang.String' to type 'domain.model.product.Product'; nested exception is java.lang.IllegalArgumentException: No enum const class domain.model.product.Product.home
  </code></pre>
  
  <p>Is there a way to have the enum type converter to understand that lower case home is actually Home? </p>
  
  <p>I'd like to keep the url case insensitive and my Java enums with standard capital letters.</p>
  
  <p>Thanks</p>
  
  <p><strong>Solution</strong></p>
  
  <pre><code>public class ProductEnumConverter extends PropertyEditorSupport
  {
      @Override public void setAsText(final String text) throws IllegalArgumentException
      {
          setValue(Product.valueOf(WordUtils.capitalizeFully(text.trim())));
      }
  }
  </code></pre>
  
  <p>registering it </p>
  
  <pre><code>&lt;bean class="org.springframework.beans.factory.config.CustomEditorConfigurer"&gt;
          &lt;property name="customEditors"&gt;
              &lt;map&gt;
                  &lt;entry key="domain.model.product.Product" value="domain.infrastructure.ProductEnumConverter"/&gt;
              &lt;/map&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>Add to controllers that need special conversion</p>
  
  <pre><code>@InitBinder
  public void initBinder(WebDataBinder binder)
  {
      binder.registerCustomEditor(Product.class, new ProductEnumConverter());
  } 
  </code></pre>