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

  • BeanWrapper issue

    It seems that registration of custom editors in BeanWrapperImpl
    doesn't work as expected (or I'm missing some important point).
    Consider the following example:

    1. SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
    2. CustomDateEditor dateEditor = new CustomDateEditor(dateFormat, false);
    3. Company company = new Company();        
    4. BeanWrapperImpl bw = new BeanWrapperImpl(company);
    5. bw.registerCustomEditor(null, "employees.birthDate", dateEditor);
    6. bw.setPropertyValue("employees", new HashMap());
    7. bw.setPropertyValue("employees[id1]", new Person());
    8. bw.setPropertyValue("employees[id1].birthDate", "10.10.1990");
    In this example, in line 5 NullPointerException is thrown (probably
    wrong exception, but this is not important for my point). After some
    Spring code inspection, it seems to me that editor registration is
    available only on maps (and list) already filled with elements,
    which means that you can not define editors upfront. Furthermore,
    it seems that even if you setup maps/lists before registration of
    editors, and after registration add some more elements, newly added
    elements will not be edited via property editors.
    Can anybody comment, please? Is there some workaround maybe?

    Damir Murat

  • #2
    Since my last post, I've done some code patching on original BeanWrapperImpl
    to make him satisfy my needs. Here is list of features that I need, and
    original BeanWrapperImpl doesn't seem to supports it (or I'm using it in
    very wrong way )
    - It is impossible to register property specific custom property editors
    if properties are in nested path which contains null elements. This
    effectively disables complex upfront registration of custom property editors.
    - On newly added elements to map/list property editor configuration doesn't
    apply. I.e. if you configure property editor for all map elements, it will
    be applied to all current map members, but if you latter add new elements
    they will not have a corresponding property editor.
    - You can not mix configuration for map and their elements.

    It would be very nice that BeanWrapperImpl supports those (I hope it will in
    future). Meanwhile, I managed to implement patch which does (at least I
    believe so). I also run it through unit tests in 'org.springframework.beans'
    package without problems.

    Unfortunately, attachments can't be posted here, so if anyone is interested,
    I will be more than happy to send code via email or something.



    • #3
      I stumbled upon the registration of editors for nested paths containing null values a while ago as well.

      You can insert your comments in JIRA and attach the patch to it. The BeanWrapper is juergen's domain so he'll have a look at it.



      • #4
        Alef, thanks for pointing me to JIRA. I've posted patch there under title 'BeanWrapper support for registration of editors for nested paths containing null values'.