Hello all
I’m trying to create a tree from database, create a form to edit some fields, and save back the pojo to database.
I managed to create the tree, however, i have problems with the form, and the tree update after the form is commited.
If i load the data into the tree with
......
Tree categories = new Tree();
categories.setImmediate(true);
categories.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
showNotification(event);
}
});
List<Category> lst = categoryManager.getCategories();
for (int i = 0; i < lst.size(); i++) {
Category c = lst.get(i);
categories.addItem(c);
categories.setChildrenAllowed(c, false);
categories.setParent(c, category);
loadChildCategories(c);
}
.......
then, if i create a form, and use the tree item to populate it, i get an empty form
public void showNotification(ValueChangeEvent event) {
Form form = new Form();
form.setCaption("Category Editor");
form.setItemDataSource(categories.getItem(categories.getValue()));
.........
Button okbutton = new Button("Save", form, "commit");
okbutton.addListener(new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
categories.commit();
Item itm = categories.getItem(categories.getValue());
for (Iterator it = itm.getItemPropertyIds().iterator(); it.hasNext();) {
Object object = it.next();
System.out.println("IDs "+object);
}
}
});
okbar.addComponent(okbutton);
form.getFooter().addComponent(okbar);
.......
Also, i get no ids when the save button is pressed.
However, if i add to the tree
new BeanItem(category)
, i get the form, but, then on commit, the tree is not updated with the changed values.
I’m missing something?