Table content and removing issue

Hello there,

I have a little problem with a table and was wondering if you could help me out here?
I have a class which is called Contact. Contact has several attributes like id, name, description etc.
Then in an other class I create a table, which has only one property called Contacts.


 table = new Table();
 table.setHeight("400px");
 table.setWidth("150px");
 table.setSelectable(true);
 table.setMultiSelect(false);
 table.setImmediate(true);
 table.addContainerProperty("Contacts", String.class, null);

Contacts are added to the table the following way:


 Set<Contact> contacts = user.getContacts();
 int i = 1;
 for(Contact c : contacts) {
   Label label = new Label(c.getName());
   label.setWidth("145px"); // doesn't work?
   Item item = ctable.addItem(new Object[] { label }, new Integer(i));
   i++;
 }

I have added a remove-action to the table, which is called when a user clicks right on an table-entry and selects remove. This calles my removeContact-Method. And this is where i need help.
What I want to do inside of this Method is something like that:


private void removeContact(Object target) {
 // get the selected Item
 Item item = table.getItem(target);
 // and get the contact bound to that item so i can remove the contact by its ID
 // something like 
 Contact contact = item.getBoundContact();
 user.removeContact(contact.getId());
}

I don’t understand the data-binding things in the book of vaadin. Its explanation is way to complex and to technical for me. Maybe you guys can help me out here? Just to make things clear, I want the user only to see the Name of the contact in the table and by right-clicking the name the user should be able to remove the contact. The user may never see the ID or other stuff of the contact. How do I do this?

Thank you!

Ok, solved the problem myself :slight_smile:
Just replaced the Integer with the contact-id.
For those who have the same problem, I did it the following way:


Set<Contact> contacts = user.getContacts();
int i = 1;
for(Contact c : contacts) {
   Label label = new Label(c.getName());
   label.setWidth("145px"); // doesn't work?
   Item item = ctable.addItem(new Object[] { label }, [color=#f41f26]
c.getId()
[/color]);
   i++;
}

Good luck and have fun :slight_smile: