Results 1 to 4 of 4

Thread: BeanWrapper issue

  1. #1

    Default 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:

    Code:
    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?

    Regards
    Damir Murat

  2. #2

    Default

    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.

    Regards
    Damir

  3. #3
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    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.

    alef

  4. #4

    Default

    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'.

    Damir

Similar Threads

  1. Replies: 7
    Last Post: Feb 1st, 2007, 01:47 AM
  2. Workaround for BeanUtils Issue in Spring??
    By tdanecito in forum Container
    Replies: 4
    Last Post: Apr 5th, 2006, 02:26 PM
  3. Replies: 5
    Last Post: Aug 11th, 2005, 02:38 AM
  4. Can BeanWrapper resolve Maps with non-string keys?
    By debradley@gmail.com in forum Swing
    Replies: 1
    Last Post: Aug 7th, 2005, 05:55 PM
  5. Replies: 3
    Last Post: Dec 8th, 2004, 10:23 AM

Posting Permissions

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