Announcement Announcement Module
Collapse
No announcement yet.
Custom Property Editor problems Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom Property Editor problems

    Hi,

    I've read previous questions about this, and looked at the code, and seem to be doing everything right, but my property editor is not being called (CustomBooleanEditor is called instead).

    The log contains:
    Code:
    [MemberContactsController] - initBinder: ...
    ...
    [CachedIntrospectionResults] - Found property 'editable' of type [boolean]
    ...
    [BeanWrapperImpl] - Converting String to [boolean] using property editor [[email protected]79e]
    ...
    [MemberContactsController] - Data binding errors: 1
    ...
    ... Failed to convert property value of type [java.lang.String] to required type [boolean] for property 'contacts.addresses[0].editable';
    ...
    [JspServlet] - 	  Request Params: 
    ... locale = en
    ... theme = simple
    ... contacts.addresses[0].editable = Edit
    ... show = contacts
    So it's clear that:
    - the value "Edit" is being assigned to a field "editable" which should be boolean
    - that initBinder is being called.

    In initBinder I register my property editors (in a subclass of SimpleFormController):
    Code:
    	@Override
    	protected void initBinder(HttpServletRequest request,
                ServletRequestDataBinder binder)
         throws Exception {
    		logger.debug("initBinder: " + binder);
    		binder.registerCustomEditor(java.lang.Boolean.class,
    				"editable", new SubmitPropertyEditor());
    		binder.registerCustomEditor(java.lang.Boolean.class,
    				new SubmitPropertyEditor());
    	}
    And the property editor includes logging info that is never seen:
    Code:
    	@Override
    	public String getAsText() {
    		logger.debug("getAsText: " + getValue());
    		return null == getValue() ? "" : getValue().toString();
    	}
    	
    	@Override
    	public void setAsText(String value) {
    		logger.debug("setAsText: " + value);
    		setValue(Boolean.TRUE);
    	}
    Any idea what is going wrong?!

    Thanks,
    Andrew

  • #2
    well well.

    turns out that boolean.class is not synonymous with java.lang.Boolean.class.

    i assumed that autoboxing made it so. but if i register the editor with boolean.class then everything works.

    heh.

    Comment


    • #3
      just in case anyone uses this as an example - if you are specifying the path name then you appear to need both the first and last components, at least. so in my case the field being assigned was contacts.addresses[0].editable - the property editors works if registered with path "contacts.addresses.editable", but not for "editable" alone. looking at the source, "contacts.editable" should work too, i think, although i haven't tried it.

      Comment

      Working...
      X