Search code examples
gwtgwtp

How to reveal default place from canReveal()


Here scenario is when unauthorized user tries to access the place i want user to navigate to the default page.In my case one place is having access to only admin user, so when non-admin user try to access this place canReveal() method gets called.Here i am trying to reveal default place from canReveal() method but instead of revealing default place its again calling revealUnauthorised() place and updating url but not revealing the default page.Is there any way around here? below is my code canReveal():

 @Override
    public boolean canReveal()
    {
        boolean canReveal = false;

        IModelObject userSession = KernelGinjector.INSTANCE.getSession().getClientDataModel().getUserSessionObject();
        if( userSession != null )
        {
            IProperty<?> contextGroup = userSession.getPropertyObject( IAdminGatekeeper.GROUP );
            if( contextGroup != null )
            {
                String group = contextGroup.getDisplayValue();

                if( group.compareToIgnoreCase( IAdminGatekeeper.DBAGroup ) != 0 )
                {
                    PlaceRequest placeRequest = new PlaceRequest(
                           showGatewaySubLocation );
                    m_uiService.getPlaceManager().revealPlace( placeRequest, true );
 }
                else
                {
                    canReveal = true;
                }
            }
        }

        return canReveal;
    }

Implementation of reveal place:

 @Override
    public void revealPlace( final PlaceRequest request, final boolean updateBrowserUrl )
    {
        if( !request.getNameToken().equals( getCurrentPlaceRequest().getNameToken() ) && m_leavePlaceHandler != null )
        {
            m_leavePlaceHandler.handleLeavePlace( new AsyncCallbackWithContextPair<PlaceRequest, Boolean, Void>(
                    request, Boolean.valueOf( updateBrowserUrl ) )
            {
                @Override
                public void onSuccess( PlaceRequest placeRequest, Boolean bUpdateBrowserUrl, Void result )
                {
                    internalRevealPlace( placeRequest, bUpdateBrowserUrl.booleanValue() );
                }

                @Override
                public void onFailure( PlaceRequest placeRequest, Boolean bUpdateBrowserUrl, Throwable caught )
                {
                    Logger.getLogger( UIPlaceManager.class.getName() ).log( Level.SEVERE, caught.getLocalizedMessage(),
                            caught );
                }
            } );
        }
        else
        {
            internalRevealPlace( request, updateBrowserUrl );
        }
    }

Solution

  • Did you have a look at the @UnauthorizedPlace annotation (https://github.com/ArcBees/GWTP/wiki/PlaceManager) ?

    You can use that to set it to the same place as the DefaultPlace

    bindConstant().annotatedWith(UnauthorizedPlace.class).to(NameTokens.defaultPlaceToken);