dmurat
Aug 18th, 2004, 11:18 AM
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?
Regards
Damir Murat
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?
Regards
Damir Murat