PDA

View Full Version : [FNR] BeanModelGenerator wrap list in a list on set() for non BeanModel items



zalant
17 Sep 2010, 2:54 AM
GXT v2.2.0

When set a list in BeanModel and items of this list are not instances of BeanModel then the list is wrapped in a new list.


public class TestBean implements BeanModelTag {

private List<String> list;

public List<String> getList() {
return list;
}

public void setList(List<String> list) {
this.list = list;
}
}

public class Test implements EntryPoint {

@Override
public void onModuleLoad() {
TestBean bean = new TestBean();
BeanModel beanModel = BeanModelLookup.get().getFactory(TestBean.class).createModel(bean);
List<String> originalList = new ArrayList<String>();
originalList.add("Hello");
originalList.add("World");

beanModel.set("list", originalList);
List<?> resultList = beanModel.get("list");

GWT.log("originalList: " + originalList.toString());
GWT.log("resultList: " + resultList.toString());
}
}Output:
originalList: [Hello, World]
resultList: [[Hello, World], [Hello, World]]

The problem is in BeanModelGenerator.createSetMethods line 296:

protected void createSetMethods(List<JMethod> properties, SourceWriter sw, String typeName) {
. . .
sw.println("} else if (obj instanceof java.util.List) {");
sw.println("java.util.List list = new java.util.ArrayList();");
sw.println("for(Object o : (java.util.List) obj) {");
sw.println("if(o instanceof BeanModel) {");
sw.println("list.add(((BeanModel) o).getBean());");
sw.println("} else {");
sw.println("list.add(obj);"); // NOTE: Here should be "list.add(o);"
sw.println("}");
sw.println("}");
sw.println("obj = list;");
sw.println("}");
. . .

sven
17 Sep 2010, 3:02 AM
Thanks for the report. there was already a patch pending. Fixed in SVN as of revision 2232