tb1.setNestedIndexedBean(new IndexedTestBean());
tb2.setNestedIndexedBean(new IndexedTestBean());
tb3.setNestedIndexedBean(new IndexedTestBean());
tb4.setNestedIndexedBean(new IndexedTestBean());
tb5.setNestedIndexedBean(new IndexedTestBean());
BeanWrapper bw = new BeanWrapperImpl(bean);
bw.registerCustomEditor(String.class, "array.nestedIndexedBean.array.name", new PropertyEditorSupport() {
public void setAsText(String text) throws IllegalArgumentException {
setValue("array" + text);
}
public String getAsText() {
return ((String) getValue()).substring(5);
}
});
bw.registerCustomEditor(String.class, "list.nestedIndexedBean.list.name", new PropertyEditorSupport() {
public void setAsText(String text) throws IllegalArgumentException {
setValue("list" + text);
}
public String getAsText() {
return ((String) getValue()).substring(4);
}
});
bw.registerCustomEditor(String.class, "map.nestedIndexedBean.map.name", new PropertyEditorSupport() {
public void setAsText(String text) throws IllegalArgumentException {
setValue("map" + text);
}
public String getAsText() {
return ((String) getValue()).substring(4);
}
});
assertEquals("name0", tb0.getName());
assertEquals("name1", tb1.getName());
assertEquals("name2", tb2.getName());
assertEquals("name3", tb3.getName());
assertEquals("name4", tb4.getName());
assertEquals("name5", tb5.getName());
assertEquals("name0", bw.getPropertyValue("array[0].nestedIndexedBean.array[0].name"));
assertEquals("name1", bw.getPropertyValue("array[1].nestedIndexedBean.array[1].name"));
assertEquals("name2", bw.getPropertyValue("list[0].nestedIndexedBean.list[0].name"));
assertEquals("name3", bw.getPropertyValue("list[1].nestedIndexedBean.list[1].name"));
assertEquals("name4", bw.getPropertyValue("map[key1].nestedIndexedBean.map[key1].name"));
assertEquals("name5", bw.getPropertyValue("map['key2'].nestedIndexedBean.map[\"key2\"].name"));
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue("array[0].nestedIndexedBean.array[0].name", "name5");
pvs.addPropertyValue("array[1].nestedIndexedBean.array[1].name", "name4");
pvs.addPropertyValue("list[0].nestedIndexedBean.list[0].name", "name3");
pvs.addPropertyValue("list[1].nestedIndexedBean.list[1].name", "name2");
pvs.addPropertyValue("map[key1].nestedIndexedBean.map[\"key1\"].name", "name1");
pvs.addPropertyValue("map['key2'].nestedIndexedBean.map[key2].name", "name0");
bw.setPropertyValues(pvs);
assertEquals("arrayname5", tb0.getNestedIndexedBean().getArray()[0].getName());
assertEquals("arrayname4", tb1.getNestedIndexedBean().getArray()[1].getName());
assertEquals("listname3", ((TestBean) tb2.getNestedIndexedBean().getList().get(0)).getName());
assertEquals("listname2", ((TestBean) tb3.getNestedIndexedBean().getList().get(1)).getName());
assertEquals("mapname1", ((TestBean) tb4.getNestedIndexedBean().getMap().get("key1")).getName());
assertEquals("mapname0", ((TestBean) tb5.getNestedIndexedBean().getMap().get("key2")).getName());
assertEquals("arrayname5", bw.getPropertyValue("array[0].nestedIndexedBean.array[0].name"));
assertEquals("arrayname4", bw.getPropertyValue("array[1].nestedIndexedBean.array[1].name"));
assertEquals("listname3", bw.getPropertyValue("list[0].nestedIndexedBean.list[0].name"));
assertEquals("listname2", bw.getPropertyValue("list[1].nestedIndexedBean.list[1].name"));
assertEquals("mapname1", bw.getPropertyValue("map['key1'].nestedIndexedBean.map[key1].name"));
assertEquals("mapname0", bw.getPropertyValue("map[key2].nestedIndexedBean.map[\"key2\"].name"));
}