Results 1 to 5 of 5

Thread: java.lang.Boolean use in form

  1. #1
    Join Date
    Mar 2007
    Location
    Richmond, VA
    Posts
    34

    Question java.lang.Boolean use in form

    I have a problem with form objects that have java.lang.Boolean data types that use the "is" construct for getter method names. I am getting the following error:

    Code:
    2007-04-24 12:43:38,737 [http-9090-Processor25] ERROR org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/webta].[webta] - Servlet.service() for servlet webta threw exception
    org.springframework.beans.NotReadablePropertyException: Invalid property 'user.accessibilityRequired' of bean class [UserMaintenanceForm]: Bean property 'user.accessibilityRequired' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
    	at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:534)
    	at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:526)
    	at org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:77)
    	at org.springframework.validation.AbstractBindingResult.getFieldValue(AbstractBindingResult.java:337)
    	at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:117)
    	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:179)
    	at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.resolveCssClass(AbstractHtmlElementTag.java:502)
    	at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:479)
    	at org.springframework.web.servlet.tags.form.AbstractHtmlInputElementTag.writeDefaultAttributes(AbstractHtmlInputElementTag.java:176)
    	at org.springframework.web.servlet.tags.form.CheckboxTag.writeTagContent(CheckboxTag.java:79)
    	at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:93)
    	at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:77)
    Upon digging closer, it seems as though the java.beans.PropertyDescriptor really doesn't handle the Boolean wrapper class all that well as it does this for the "getReadMethod()":
    Code:
    ...
    		Class type = getPropertyType0();
    		if (type == boolean.class || type == null) {
    		    readMethodName = "is" + getBaseName();
    		} else {
    		    readMethodName = "get" + getBaseName();
    		}
    	    }
    ...
    As you can see, if you are not using the primitive boolean, the use of "is" is not permitted and it assumes the "get" form of the getter method. Is this a bug in JDK 1.5? With autoboxing/unboxing you would think boolean.class and Boolean.class would be interchangeable. I am currently using the "is" construct for the getter for all my java.lang.Booleans and we are at the point that this cannot be changed. Does anyone have any suggestions to get around this?

  2. #2
    Join Date
    Mar 2007
    Location
    Richmond, VA
    Posts
    34

    Default Seems to be a problem XJC and Sun isn't going to fix...

    http://www.mojavelinux.com/blog/arch...nder/index.php

    It seems as though Sun isn't going to fix this, so I need a fix. I don't think I can change our model from boolean to Boolean, so is there a clever way built into spring to handle this?

    Thanks.

  3. #3
    Join Date
    Feb 2007
    Location
    Moscow, Russia
    Posts
    56

    Default

    You can add your custom bean descriptor class and specify your own method names.

  4. #4
    Join Date
    Mar 2007
    Location
    Richmond, VA
    Posts
    34

    Default

    I scoured the javadocs looking for that option but couldn't find the ability to do that. Could you point me in the right direction?

    Thanks.

  5. #5
    Join Date
    Feb 2007
    Location
    Moscow, Russia
    Posts
    56

    Default

    Its fairly easy:

    http://java.sun.com/j2se/1.5.0/docs/.../BeanInfo.html

    Assuming that you class is MyClass, you just have to add class called MyClassBeanInfo which implements BeanInfo and overrides some property descriptors http://java.sun.com/j2se/1.5.0/docs/...etReadMethod().

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •