JPAContainer and refresh on multiple browser

Hello,

I use JPAContainer to manage a table from mysql database.

Code in view :


	@Resource
	private transient BLWLController blwlController;
	private CustomTableFormating wlTable;
	private EntityContainer<AnnuPersFauxDoublon> wlContainer;

public void init() {
wlContainer = blwlController.getWLContainer();
wlTable = new Tablenull, wlContainer);
wlTable.setSelectable(true);
wlTable.setImmediate(true);
...
some code to delete item with an action on a button
...
}

In the controller :


public JPAContainer<AnnuPersFauxDoublon> getWLContainer() {
		JPAContainer<Toto> wlContainer = JPAContainerFactory.make(Toto.class, entityManagerFactory.createEntityManager());
		wlContainer.setAutoCommit(true);
}

public synchronized void deleteWLItem(final EntityItem<Toto> wlItem) {
wlItem.getContainer().removeItem(wlItem.getItemId());
}

Everythings is fine, and when I call deleteWLItem, item is correctly deleted from database.

But, if I have two browser open, I can’t see any change in the other browser and the item deleted in the first browser is still there.
Is there any way to reflect change from browser in another? If an item is deleted in one browser, I want the item disappear in the other browser…
It is possible?

Thanks for your reply!

Hi,

Unfortunately you have to do something like periodically call refresh() on the container for it to reflect changes done in another session. Another alternative would be to pass a message on a message bus visible to all sessions / application instances and refresh whenever a relevant message is received.

So, in summary there is no ready made solution to this issue. You have to roll your own.

/Jonatan