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

  • BeanWrapper and PropertyEditors

    I'm trying to read a bean property via BeanWrapper.getPropertyValue(). I have also registered a custom editor for the property class which implements the getAsText() method. However, it seems that the custom editor method is never invoked.

    Code:
       
    BeanWrapper wrapper = new BeanWrapperImpl(object);
    wrapper.registerCustomEditor(Carrier.class, new PropertyEditorSupport() {     
          public String getAsText() {
            Carrier c = (Carrier)getValue();
            String result =  (c != null) ? c.getName() : null;
            return result;
          }
    });
    Object value = wrapper.getPropertyValue(fieldName);
    Am I doing something wrong or is this behaviour by design?

    Thanks, Juergen

  • #2
    The getPropertyValue() method returns just the value of the property as is. The main use of the PropertyEditor is the ability to set the property value from a string value (e.g. from within a spring configuration file).

    So if you like to have the string representation I think you will have to apply the PropertyEditor yourself.

    Regards,
    Andreas

    Comment


    • #3
      Andreas, thanks for your reply. Wouldn't it extend the usefulness of BeanWrapper if PropertyEditors were also applied for getting properties?

      Juergen

      Comment


      • #4
        For direct use of the BeanWrapper I hadn't the need to access the stringified version of a bean property so far (though I do not use BeanWrapper directly very often).

        I guess there is some support for this in Spring's WebUI (since there such a feature would indeed be required). However I haven't used this part of Spring, so I cannot provide you with more details on that.

        Regards,
        Andreas

        Comment

        Working...
        X