0

I have a JPAContainer filled with group entities (which contains properties like group name, number of users in the group, etc). I want users to be able to view a table containing a list of all the groups they belong to.

I got this to work by doing groups.addContainerFilter(new Like("users.email", user.getEmail())); (Just realized using their ID would have made more sense, but that's not the point), but now I'm having the issue where if there are two users viewing the table at the same time, the listed groups will change to the new user's groups.

For example:

  • Player A is viewing his groups
  • Player B goes to view his groups
  • Player A's view refreshes
  • Player A is now viewing player B's groups

I feel like I'm missing an obvious solution. I thought of just having a separate container backing the table, and then adding all the entities resulting from the filter on groups to the table's new container, but that seems inefficient.

Is it not possible to somehow have the same JPAContainer be filtered differently for different users?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Zout
  • 821
  • 10
  • 18
  • 1
    I think you are using the container at the application level, instead of user level. Usually this should be done in the class extending the vaadin UI class, so you get a instance be active session. – André Schild Mar 15 '15 at 17:34

1 Answers1

0

Well, I decided to go with my first idea for a solution, and just add the groups to a separate container backing the table. If anyone has a better solution I'd love to hear it.

This is basically how I made it work:

BeanItemContainer<Group> tableBack = new BeanItemContainer<Group>(Group.class);
groupTable.setContainerDataSource(tableBack);
Filter loggedInFilter = GroupManager.getGroupsByUserFilter(UserManager.getLoggedInUser());
tableBack.addAll(GroupManager.applyFiltersGetResults(loggedInFilter));

Where applyFiltersGetResults() applies an array of filters to the JPAContainer and returns a list of all the groups matching them.

Edit: That was a bad solution. Originally I had a static JPAcontainer used for all UI instances, but now a new container is initialized per UI, which allows for filtering without affecting the container for others. I'd thought this wouldn't let people see other users, but it works fine.

Zout
  • 821
  • 10
  • 18