assertEquals("mapname0", bw.getPropertyValue("map['key2'].name"));
}
public void testIndexedPropertiesWithIndividualCustomEditorForProperty() {
IndexedTestBean bean = new IndexedTestBean(false);
BeanWrapper bw = new BeanWrapperImpl(bean);
bw.registerCustomEditor(String.class, "array[0].name", new PropertyEditorSupport() {
public void setAsText(String text) throws IllegalArgumentException {
setValue("array0" + text);
}
});
bw.registerCustomEditor(String.class, "array[1].name", new PropertyEditorSupport() {
public void setAsText(String text) throws IllegalArgumentException {
setValue("array1" + text);
}
});
bw.registerCustomEditor(String.class, "list[0].name", new PropertyEditorSupport() {
public void setAsText(String text) throws IllegalArgumentException {
setValue("list0" + text);
}
});
bw.registerCustomEditor(String.class, "list[1].name", new PropertyEditorSupport() {
public void setAsText(String text) throws IllegalArgumentException {
setValue("list1" + text);
}
});
bw.registerCustomEditor(String.class, "map[key1].name", new PropertyEditorSupport() {
public void setAsText(String text) throws IllegalArgumentException {
setValue("mapkey1" + text);
}
});
bw.registerCustomEditor(String.class, "map[key2].name", new PropertyEditorSupport() {
public void setAsText(String text) throws IllegalArgumentException {
setValue("mapkey2" + text);
}
});
bean.populate();
TestBean tb0 = bean.getArray()[0];
TestBean tb1 = bean.getArray()[1];
TestBean tb2 = ((TestBean) bean.getList().get(0));
TestBean tb3 = ((TestBean) bean.getList().get(1));
TestBean tb4 = ((TestBean) bean.getMap().get("key1"));
TestBean tb5 = ((TestBean) bean.getMap().get("key2"));
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].name"));
assertEquals("name1", bw.getPropertyValue("array[1].name"));
assertEquals("name2", bw.getPropertyValue("list[0].name"));
assertEquals("name3", bw.getPropertyValue("list[1].name"));
assertEquals("name4", bw.getPropertyValue("map[key1].name"));
assertEquals("name5", bw.getPropertyValue("map[key2].name"));
assertEquals("name4", bw.getPropertyValue("map['key1'].name"));
assertEquals("name5", bw.getPropertyValue("map[\"key2\"].name"));
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue("array[0].name", "name5");
pvs.addPropertyValue("array[1].name", "name4");
pvs.addPropertyValue("list[0].name", "name3");
pvs.addPropertyValue("list[1].name", "name2");
pvs.addPropertyValue("map[key1].name", "name1");
pvs.addPropertyValue("map['key2'].name", "name0");
bw.setPropertyValues(pvs);
assertEquals("array0name5", tb0.getName());
assertEquals("array1name4", tb1.getName());
assertEquals("list0name3", tb2.getName());
assertEquals("list1name2", tb3.getName());
assertEquals("mapkey1name1", tb4.getName());
assertEquals("mapkey2name0", tb5.getName());
assertEquals("array0name5", bw.getPropertyValue("array[0].name"));
assertEquals("array1name4", bw.getPropertyValue("array[1].name"));
assertEquals("list0name3", bw.getPropertyValue("list[0].name"));
assertEquals("list1name2", bw.getPropertyValue("list[1].name"));
assertEquals("mapkey1name1", bw.getPropertyValue("map[\"key1\"].name"));
assertEquals("mapkey2name0", bw.getPropertyValue("map['key2'].name"));
}