Good afternoon guys!
I’m a little lost on this one. I’m still learning all this stuff, so help is much appreciated.
When I press ‘save’, that calls form.commit(). I pretty much took this out of the addressbook example.
I have a table with 2 rows, 5 columns, all containing numbers:
20 1 2 1 1
7 6 5 4 3
Say I want to update the second row with this value:
7 6 45 4 3
This is what ends up happening to my container:
20 1 2 1 1
null
Here is my code, and debug to go along with it. Anyone have any ideas? Note that neither my Model Class, nor Item are null. Also, after committing, the table sees that it is updated, but only makes an empty row in the display view.
BEFORECOMMIT
Entry Form:7 6 5 4 3
---
Editting Model:[3, 4, 7, 6, 5]
---
Table:[3, 4, 7, 6, 5]
Container:
20 1 2 1 1
7 6 5 4 3
AFTERCOMMIT
Entry Form:7 6 45 4 3
---
Editting Model:[3, 4, 7, 6, 45]
---
Table:[3, 4, 7, 6, 45]
---
Container:
20 1 2 1 1
null
END COMMIT
...
...
if (source == save) {
/* If the given input is not valid there is no point in continuing */
if (!entryForm.isValid()) {
return;
}
System.out.println("BEFORECOMMIT");
System.out.println("Entry Form:" + entryForm.getItemDataSource());
System.out.println("---");
System.out.println("Editting Model:" + editting);
System.out.println("---");
System.out.println("Table:" + tableList.getValue());
System.out.println("Container:");
for (Object id : bic.getItemIds())
{
System.out.println(bic.getItem(id));
}
entryForm.commit();
System.out.println("AFTERCOMMIT");
System.out.println("Entry Form:" + entryForm.getItemDataSource());
System.out.println("---");
System.out.println("Editting Model:" + editting);
System.out.println("---");
System.out.println("Table:" + tableList.getValue());
bic = (BeanItemContainer<Model>)tableList.getContainerDataSource();
System.out.println("---");
System.out.println("Container:");
for (Object id : bic.getItemIds())
{
System.out.println(bic.getItem(id));
}
System.out.println("END COMMIT");
if (createNew) {
/* We need to add the new person to the container */
System.out.println("GET DATA SOURCE");
Container c = tableList.getContainerDataSource();
System.out.println("ADD ITEM");
Item addedItem = c.addItem(editting);
tableList.setContainerDataSource(c);
/*
* We must update the form to use the Item from our datasource
* as we are now in edit mode (no longer in add mode)
*/
System.out.println("SET DATA SOURCE");
entryForm.setItemDataSource(addedItem,ModelMetadata.getPropertyNames(editting.getClass()));
entryForm.setItemDataSource(addedItem);
createNew = false;
}
entryForm.setReadOnly(true);
create.setVisible(true);
edit.setVisible(true);
cancel.setVisible(false);
save.setVisible(false);
delete.setVisible(false);
}
...
...