PDA

View Full Version : [CLOSED]treetable.getItemById



doud
30 Jul 2008, 3:42 PM
Maybe I don't understand the way it works
setItemId/getItemById and setId/getItemById return NullPointerException




public class Test implements EntryPoint {

/**
* This is the entry point method.
*/
public void onModuleLoad() {

LayoutContainer lc = new LayoutContainer();
lc.setLayout(new FitLayout());

List<TreeTableColumn> columns = new ArrayList<TreeTableColumn>();
columns.add(new TreeTableColumn("0", 50));
columns.add(new TreeTableColumn("1", 50));
columns.add(new TreeTableColumn("2", 50));

TreeTableColumnModel cm = new TreeTableColumnModel(columns);
TreeTable tree = new TreeTable(cm);

TreeTableItem treeItem = new TreeTableItem(new Object[3]);
tree.getRootItem().add(treeItem);
treeItem.setText("item1");
treeItem.setValue(1, "one");
treeItem.setValue(2, "two");
treeItem.setId("id");

TreeTableItem treeItem2 = new TreeTableItem(new Object[3]);
treeItem.setText("item2");
treeItem2.setValue(1, "one");
treeItem2.setValue(2, "two");
tree.getItemById("id").add(treeItem2);

lc.add(tree);
RootPanel.get().add(lc);
}
}

gslender
30 Jul 2008, 6:30 PM
you need to set the id on the treeitem before you add the item to the tree - not really a bug so can you close this (ie change the title to say [CLOSED])

doud
31 Jul 2008, 12:03 AM
Thanks, maybe you can help me for this too.
getItemByItemId(id).getId();
getItemByItemId(id).getDepth();
getItemByItemId(id).toString();

return a null pointer exception

but getItemByItemId(id).add() work well.




public class Test implements EntryPoint {

/**
* This is the entry point method.
*/
public void onModuleLoad() {

LayoutContainer lc = new LayoutContainer();
lc.setLayout(new FitLayout());

List<TreeTableColumn> columns = new ArrayList<TreeTableColumn>();
columns.add(new TreeTableColumn("0", 50));
columns.add(new TreeTableColumn("1", 50));
columns.add(new TreeTableColumn("2", 50));

TreeTableColumnModel cm = new TreeTableColumnModel(columns);
TreeTable tree = new TreeTable(cm);

String id = "id";

TreeTableItem treeItem = new TreeTableItem(new Object[3]);
treeItem.setId(id);
treeItem.setText("asdfasdf");
tree.getRootItem().add(treeItem);
treeItem.setText("item1");
treeItem.setValue(1, "one");
treeItem.setValue(2, "two");

TreeTableItem treeItem2 = new TreeTableItem(new Object[3]);
treeItem.setText("item2");
treeItem2.setValue(1, "one");
treeItem2.setValue(2, "two");

tree.getItemById(id).add(treeItem2); // No problem..

if(tree.getItemById(id) instanceof TreeTableItem) {
System.out.println("yes");
System.out.println("itemid " + tree.getItemByItemId(id).getId()); // Null Exception
} else {
System.out.println("no");
}

lc.add(tree);
RootPanel.get().add(lc);
}
}

this code print 'yes' and ... bam.

gslender
31 Jul 2008, 1:42 AM
you've used the wrong method...

the line....


System.out.println("itemid " + tree.getItemByItemId(id).getId()); // Null Exception

should be


System.out.println("itemid " + tree.getItemById(id).getId()); // <<< note the correct use of tree.getItemById

How about we end this here and you re-post further help questions in the help forum.