title: Spring 3 Custom Editor field replacement
body: <p>Having my ValueObject</p>
  
  <pre><code>UserVO {
    long id;
    String username;
  }
  </code></pre>
  
  <p>I created custom editor for parsing this object from string id#username</p>
  
  <pre><code>public class UserVOEditor extends PropertyEditorSupport {
  
  @Override
  public void setAsText(String text) throws IllegalArgumentException {
      Preconditions.checkArgument(text != null,"Null argument supplied when parsing UserVO");
      String[] txtArray = text.split("\\#");
      Preconditions.checkArgument(txtArray.length == 2, "Error parsing UserVO. Expected: id#username");
      long parsedId = Long.valueOf(txtArray[0]);
      String username = txtArray[1];
      UserVO uvo = new UserVO();
      uvo.setUsername(username);
      uvo.setId(parsedId);
      this.setValue(uvo);
  }
  
  @Override
  public String getAsText() {
      UserVO uvo = (UserVO) getValue();
      return uvo.getId()+'#'+uvo.getUsername();
  }
  </code></pre>
  
  <p>in my controller i register </p>
  
  <pre><code>@InitBinder
  public void initBinder(ServletRequestDataBinder binder) {
      binder.registerCustomEditor(UserVO.class, new UserVOEditor());
  }
  </code></pre>
  
  <p>having in my model object ModelVO</p>
  
  <pre><code>ModelVO { 
             Set&lt;UserVO&gt; users = new HashSet&lt;UserVO&gt;();
  }
  </code></pre>
  
  <p>after custom editor is invoked all you can see after form submission is</p>
  
  <pre><code>ModelVO {
            Set&lt;String&gt; users (linkedHashSet)
  }
  </code></pre>
  
  <p>so when trying to iterate </p>
  
  <pre><code>for(UserVO uvo : myModel.getUser()){ .. }
  </code></pre>
  
  <p>Im having classCastException .. cannot cast 1234#username (String) to UserVO ..
  HOW THIS MAGIC IS POSSIBLE ?</p>