private static final long serialVersionUID = 1L;
public void headerClick(HeaderClickEvent event) {
String column = (String) event.getPropertyId();
Notification.show("Clicked " + column +
"with " + event.getButtonName());
ttable.sort(new String{column}, new boolean {true});
}
});
[/code]I have error:
Caused by: java.lang.UnsupportedOperationException: Underlying Data does not allow sorting
at com.vaadin.ui.Table.sort(Table.java:4712)
the HierarchicalContainerOrderedWrapper class does not implement Container.Sortable interface which is required for the sorting to work. So you need to either make a customized container implementation that implements Sortable, or use HierarchicalContainer. There’s currently no “HierarchicalBeanItemContainer” available as far as I know. You could look at some pointers at
https://dev.vaadin.com/svn/doc/book-examples/trunk/src/com/vaadin/book/examples/datamodel/HierarchicalExample.java where such a thing is implemented.
As for the filtering, you can just create your own Filter objects from actions on your menubar and then set them to the container. This will ofcourse require that your container implements the Container.Filterable interface.
why do you want to wrap a wrapper?
I didn’t test it out but you may want to extend ContainerHierarchicalWrapper and except an AbstractBeanContainer as constructor parameter/as delegator. So you can let the delegator do the sorting thing. That would be my first approach.
providing pointers for all those methods is quite a task :).
Please see the code I linked earlier and especially the HierarchicalBeanItemContainer implemented within it. It implements Hierarchical and extends BeanItemContainer which is already Sortable and Filterable, so I think this should do what you need. You might even be done by just copy-pasting that exact implementation.
Yes, you can do it this way, I just don’t get why you want to do work that’s already been done. Basically what you need to do is just forward those method calls to the actual container. Since the underlying container is a BeanItemContainer those methods are already implemented there. If you’re going this way, you should probably change the constructor parameter type to something else than Hierarchical, since that alone does not provide access to Sortable/Filterable, even though the underlying BeanItemContainer implements those.
The main difference is that you can’t use beans/BeanItems as the items in the container. This should not be an issue - you can just use the bean itself as the itemid. Remember that if you do that ,your bean should implement hashCode and equals methods properly.