Retrieving elements in order in a table

Hi all,

First of all sorry if the question has been already asked in this forum but I couldn’t find any reply.

My situation is the following: I have a table in Vaadin that has many items on them. The user can remove / add items from that table at any position of the table and sort by any column he wants.

I then want to be able to loop the table and get the elements in the same order that are being displayed to the user. How can I do so?

I’ve tried:

		ArrayList<String> operations = new ArrayList<String>();
		Collection<TestCaseBean> inputItemIds = (Collection<TestCaseBean>) destinyTable.getItemIds();
		for (TestCaseBean itemId : inputItemIds) {
		return operations;

The problem is that when I do this the order of the elements seems to be completely random. Is not the order in which they were added to the table in first place neither the displaying order.

Does anyone know any way to get the elements in the exact order as they are being displayed to the user?

Thanks a lot!

Do you use a custom container?
The contract of getItemIds says:

Is your container ordered / sortable?

The API for getItemIds() state:

     * Gets the ID's of all visible (after filtering and sorting) Items stored
     * in the Container. The ID's cannot be modified through the returned
     * collection.
     * If the container is {@link Ordered}, the collection returned by this
     * method should follow that order. If the container is {@link Sortable},
     * the items should be in the sorted order.
     * Calling this method for large lazy containers can be an expensive
     * operation and should be avoided when practical.
     * @return unmodifiable collection of Item IDs
    public Collection<?> getItemIds();

So if the container impoements Container.Sortable then getItemIds should return in the same order that the user sees them. If not then it is either a bug in the container or in the JavaDocs. Which container are you using?


I’m in the same case, i’m using a Table with HierarchicalContainer and I would like to retrieve items from container in the shown order. I’ve used getItemIds() method but it doesn’t return the wanted order.

I use container.moveAfterSibling(sourceItem, targetItem) to reorder table.