Search code examples
gwtgwt-platform

GWT-Platform Gatekeeper and Nested Presenters


I would like to know some things about gwtp gatekeeper:

  1. if canReveal() method returns false, what happens? In my tests, i've been redirected to the defaultplace, i can change it?

  2. having nested presenters, like:

    MenuPresenter - Only visible for admins.

    HomePresenter - Visible for admins and normal users.

    When the logged user is a normal user, i want to only "not display" the menu presenter, is that possible?

thanks


Solution

  • 1 - "if canReveal() method returns false, what happens? In my tests, i've been redirected to the defaultplace, i can change it?"

    From the GWTP wiki:

    "The presenter handling errors is the one revealed by your custom PlaceManager's revealErrorPlace method. If you do not override that method, then it's the one revealed by your revealDefaultPlace method."

    This is the default implementation of revealErrorPlace:

    public void revealErrorPlace(String invalidHistoryToken) {
        revealDefaultPlace();
    }
    

    So you can override it in your custom PlaceManager and add more logic to it to redirect to any place you want.


    2 - "When the logged user is a normal user, i want to only "not display" the menu presenter, is that possible?"

    You can hide the view in the presenter like this:

    @Override
    protected void onReset() {
        super.onReset();
    
        if (!user.getAdmin) {
            getView().asWidget().setVisible(false);
       }
    }
    

    (for PopupPresenters you must override the onReveal() method)