How to apply a Filter to a BeanItemContainer

Hi,
I’ve the problem that I want to create a table with the help of a container which displays a class (for example a person) which has a List of other classes (for example Departments. i.e. a ManytoMany relation) and I want to be able to use a filter in such way that only persons who for example are in department x are shown in the table.

For this purpose I used a JpaContainer and the following function works perfectly to display only the persons, which have the filterelement in der departsments list:

private void updateFilters(){ jpaContainer.removeAllContainerFilters(); if(filterElement != null){ Filter filter = new Compare.Equal("departments", filterElement); jpaContainer.addContainerFilter(filter); } } However in some Parts of my application I don’t want the objects to be persisted to database and thus used a BeanItemContainer. However I don’t get it, to adjust the above code to work with this kind of container. If a filter is applied no Persons are shown.
Can some please explain me how to apply such filters correctly to a BeanitemContainer?
If it’s not possible to use such filters with a BeanItemContainer would be possible to use a JpaContainer with disabled database mapping?

Thanks!

I’m guessing here, but it might be that Compare.Equals doesn’t check collection content, only identity. The best way to check is to use the debugger, and put a breakpoint inside the filter.

Hi,
but why is the same filter working with a jpa container?

Unfortunately my debugging skills are not very good and i didn’t managed to find the issue. However i created a minimal example, which i attached to this post.
It contains beside the main code, which is in the MyUI.java file, the two entity classes Person and Department and a DepartmentsToStringConverter for presenting the Departsments of a Person in the table.

For testing this minimal example the files have to be put in the folder /src/java/main/test/ corresponding to the pom.
mvn package and mvn jetty:run are then enough to run this example. However for testing the jpa container, one would have to create a persistence.xml
17758.java (1.66 KB)
17759.java (4.47 KB)
17760.xml (7.11 KB)
17761.java (1.64 KB)
17762.java (1.3 KB)


Here
is some help… You can simply add a method to
FilterableTable
class like following:

void setContainerDataSource(Container newDataSource){ super.setContainerDataSource(newDataSource); } Then you can simply replace your code with the FilterableTable in the
post
.