Announcement Announcement Module
Collapse
No announcement yet.
int PropertyEditorSupport Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • int PropertyEditorSupport

    Hi all.

    I have a jsp where i recollect data from a form. The form is managed by a SimpleFormController.

    The bean to populate with the recollected data has an int property named "id".

    When the user lets the field blank or populates it with characters and submits, the system gives an error because cannot convert the String to int.

    I want to make a PropertyEditorSupport to manage this but it hasnt worked.

    The propertyEditorSupport code is:

    Code:
    public class IntegerCustomEditor extends PropertyEditorSupport {
    	/* (non-Javadoc)
    	 * @see java.beans.PropertyEditorSupport#getAsText()
    	 */
    	public String getAsText() {
    		Integer i = (Integer)getValue();
    		return i.toString(); 
    	}
    
    	/* (non-Javadoc)
    	 * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
    	 */
    	public void setAsText(String arg0) throws IllegalArgumentException {
    		if( arg0 == "" || arg0 == null ) setValue(0);
    		else setValue(Integer.parseInteger(arg0));
    	}
    }
    and the initBinder:
    Code:
    	protected void initBinder(HttpServletRequest arg0, ServletRequestDataBinder arg1) throws Exception {
    		arg1.registerCustomEditor(Integer.class, new IntegerCustomEditor());
    		super.initBinder(arg0, arg1);
    	}
    I have tried with the int.class instead of the Integer.class too but it hasn't worked either.

    Any idea? what am i doing bad?

  • #2
    http://forum.springframework.org/showthread.php?t=27158

    Comment


    • #3
      thx, i have solved it

      Comment

      Working...
      X