Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
How to use container with multiple components
Hi,
Let me first describe my scenario: I have two tabs, one displaying a table of user accounts, the other one displaying a table of user groups. Both tables are filled using a BeanItemContainer - one with accounts, one with groups. The groups table displays the number of accounts in a generated column. At the account table I have a generated column too, that creates links that than clicked open a window with group assignment functionality (TwinColSelect).
I pass the account BeanItem to the window and use it as PropertyDataSource for TwinColSelect.
accountGroupSelection = new TwinColSelect();
accountGroupSelection.setCaption("Groups");
accountGroupSelection.setNullSelectionAllowed(true);
accountGroupSelection.setMultiSelect(true);
accountGroupSelection.setImmediate(false);
accountGroupSelection.setWriteThrough(false);
accountGroupSelection.setContainerDataSource(passedGroupsItemContainer);
accountGroupSelection.setItemCaptionPropertyId("name");
accountGroupSelection.setPropertyDataSource(passedAccountItem.getItemProperty("groups"));
The TwinColSelect got the same BeanItemContainer set as ContainerDataSource than the user groups table. This works fine so far.
When updating the group <> account assignment via the TwinColSelect I do:
BeanItem<UserGroup> selectedGroupItem = passedGroupsItemContainer.getItem(selectedGroup);
Property accountsProperty = selectedGroupItem.getItemProperty("accounts");
accountsProperty.setValue(selectedGroup.getAccounts());
The issue I have is that the accounts column isn't updated after setting new property value. Maybe someone can bring me on the right path with that.
Thanks!
Michael
Hi Michael!
Do I understand you correctly in that the accounts table is displaying the list of accounts that are stored in the user group item's account property? If this is the case I think you'll have to update the accounts container manually to reflect the new state of the account property.
But it's hard to say anything for sure without more information.
HTH,
/Jonatan
Hi Jonatan,
thanks for your reply. I actually got the issue resolved. Problem was the generated column - this isn't updated automatically. Therefore I tried two things that both worked:
a) I overwrote com.vaadin.ui.Table#formatPropertyValue(java.lang.Object, java.lang.Object, com.vaadin.data.Property) to display size of groups
b) I attached a ValueChangeNotifier
Property groupsProperty = source.getContainerProperty(itemId, "groups");
// we must hook value change listener to ensure updates
if (groupsProperty instanceof Property.ValueChangeNotifier)
{
Property.ValueChangeNotifier notifier = (Property.ValueChangeNotifier) groupsProperty;
notifier.addListener(new Property.ValueChangeListener()
{
public void valueChange(Property.ValueChangeEvent event)
{
accounts.setValue((account.getGroups().size()));
}
});
}
Michael