Search code examples
gwtgwtp

GWTP: clear presenters on logout


Im using GWTP in my GWT app and have the following architecture:

LoginPresenter (Presenter)
    DashboardPresenter (TabContainerPresenter)
        TabbedPresenter1 (Presenter)
        TabbedPresenter2 (Presenter)
        TabbedPresenter3 (Presenter)

The first time I start my app, the onBind and addTab methods are called in the DashboardPresenter and when I navigate to a tab, the onbind method is called on that presenter.

If I create a PlaceRequest and navigate back to LoginPresenter via my PlaceManager (by pressing a logout button), I return to the login presenter.

The problem is that if I login again, then all the onBind methods are not called because they are still in memory. onReset and onReveal are called correctly, but I would very much like that each Presenter are reset and that the onBind will be called on each login.

I decide on the login event which tabs should be visible for user and restrict tabs in the addTab method of the DashboardPresenter if the user does not have sufficient rights to see those tabs. But as of now, the tabs are setup the first time a user logs in, but not the next time. This means that if a user with lesser rights logs in after an admin user, he can see the same tabs as the admin. Not good!

How should I deal with this? I would very much like to "reset" all presenters or the session when a user logsout (navigating to the login page). Is it the Ginjector that needs to be "reset", so that it does not return the same binded objects as before?

Just to clarify: we do have server side security which prohibits users with no rights to access sensitive data. But when the user logs in, the gwt app receives a list of features which the user can access. This is used for customizing the UI to fit the rights of the user. (E.g. customize the visible tabs based on users privileges).


Solution

  • I am not sure if this work:

    But you could try to fire a LogoutEvent on the global EventBus , handle it in all Presenters that need to be "unloaded" (TabbedPresenter1, etc) and call onUnbind() on them. Afterwards navigate back to the LoginPresenter

    Alternatively you could make us of a custom TabData (subclass TabDataBasic and add a flag hasAccess). Again you fire a LogoutEvent and when you handle it you can do something like that:

    TabDataDynamic tabData = (TabDataDynamic)getProxy().getTabData();
    tabData.setHasAccess(false);
    getProxy().changeTab(tabData);
    

    In yout TabPanel implementation you have to make sure that the Tab is hidden, when the flag is set to false.