Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Sorting Table or Container
I'm having a spot of bother with getting an updatable table view to be sorted.
I've attached a simple example app of my problem which represents my real classes (without the complications!)
Basically I have a set of Beans that I need to wrap inside a UI bean - this provides an identity based equals method instead of the full Bean's equals and also provides the comparator implementation which the sorting should use.
I place my wrapped beans in a BeanItemContainer, <MyBeanUIWrapper> .
My Table generates a view component by retrieving the base Bean.
It appears that when I add a new bean into my container I need to call the doSort method to force the updated container to sort the items, this (using an ItemSorter) calls the compareTo method on my wrapper beans and should sort the container, I expected the sorting to be represented in the actual Table itself.
Unfortunately it is not and I'm struggling to work out where the problem is, some simple debug suggests the container is not sorting, further to this, am I right in trying to sort the Container as opposed to the Table.
Any help would be appreciated.
I quickly looked at your code and it looks like the only visible column is a generated column, is this correct? If this is the case, you should note that sorting is not supported for GeneratedColumns, so this might have something to do with your troubles getting the data sorted.
Of course, I could be wrong :)
Many thanks for your reply, this is correct. the reason I have done this is because I needed a slightly more interesting UI component to display my data than simple values in a table cell/row, since I can put all my data where I want within that cell (using a composite component) I have no need to use any other columns.
In some ways the Table component seems wrong, but was the easiesat way to get a UI component list that would respond to changes from my business services, e.g. my container is registered to recieve updates from the business-tier, these are then automatically pushed to the Table.
What I have had to do to get the result I want is to invert my approach, registering my Table with the Business Services and then passing updates through to the container, the Table then knows when it needs to re-sort to accound for new data. Obvisously this is isnt the most efficient way to be passing messages around, I just dont get why I cant sort my container properly so I can maintain a purer separation between my UI and data servcies.