2012-09-19 138 views
4

在我的GWT平臺應用程序,我現在面臨一個奇怪的問題,當我運行在碼頭應用之一,在日食GWT配置方法不刷新瀏覽器調用插件並且在瀏覽器刷新當前頁面被加載(placeManager.getCurrentPlaceRequest())後成功,但是當應用程序在tomcat中部署/ jboss執行後,當前位置請求的演示者的onBind()方法停止並且不顯示頁面。GWT平臺:onReveal()當應用程序部署在Tomcat/JBoss的

在處理刷新的過程中,GateKeeper for Presenter的canReveal()方法首次返回false,服務器調用後我再次顯示當前地點,導致canReveal()方法返回true,但演示者仍然未被發現。所以,在這裏我懷疑有些棘手問題!

對此類行爲有何暗示?

以下爲實現LoggedInGatekeeper的代碼片段其中發揮了關鍵作用:

public class LoggedInGatekeeper implements Gatekeeper {

private final EventBus eventBus; 

private final DispatchAsync dispatcher; 

private final PlaceManager placeManager; 

private CurrentUser currentUser; 

private boolean isUserLoggedOut; 

private String lastPageAccessed; 

@Inject 
public LoggedInGatekeeper(final EventBus eventBus, final DispatchAsync dispatcher, final PlaceManager placeManager) 
{ 
    this.eventBus = eventBus; 

    this.dispatcher = dispatcher; 

    this.placeManager = placeManager; 

    this.eventBus.addHandler(LoginAuthenticatedEvent.getType(), new LoginAuthenticatedEventHandler() 
    { 
     @Override 
     public void onLogin(LoginAuthenticatedEvent event) 
     { 
      currentUser = event.getCurrentUser(); 
      isUserLoggedOut = false; 
     } 
    }); 

    this.eventBus.addHandler(LogoutUserEvent.getType(), new LogoutUserEventHandler() 
    { 
     @Override 
     public void onLogoutUser(LogoutUserEvent event) 
     { 
      SessionFactory.removeCookie(Constants.LAST_PAGE_ACCESSED); 
      currentUser = null; 
      isUserLoggedOut = true; 
     } 
    }); 
} 

@Override 
public boolean canReveal() 
{ 
    Log.info("Browser fetched session cookie : " + Cookies.getCookie(Constants.JSESSION_COOKIE_KEY)); 

    if (Cookies.getCookie(Constants.JSESSION_COOKIE_KEY) == null) 
    { 
     SC.say("Your session is expired. Please login again"); 
     NavigateToLoginEvent.fire(eventBus); 
     return false; 
    } 

    if (currentUser != null && !isUserLoggedOut) 
    { 

     lastPageAccessed = placeManager.getCurrentPlaceRequest().getNameToken(); 
     Log.info("canReveal() 1 : " + lastPageAccessed); 
     SessionFactory.addCookie(Constants.LAST_PAGE_ACCESSED, lastPageAccessed); 
     return currentUser.isLoggedIn(); 
    } 
    else if (isUserLoggedOut) 
    { 
     Log.info("canReveal() 2 : User is logged out"); 
     NavigateToLoginEvent.fire(eventBus); 
     return false; 
    } 
    else 
    { 
     Log.info("canReveal() 3 : Check on server for logged in user"); 
     dispatcher.execute(new FetchLoggedInUserAction(), new FetchLoggedInUserAsyncCallback()); 
     return true; 
    } 
} 

class FetchLoggedInUserAsyncCallback extends MessageAsyncCallback<FetchLoggedInUserResult> 
{ 
    /** 
    * 
    */ 
    public FetchLoggedInUserAsyncCallback() 
    { 
     super("Loading..."); 
    } 

    @Override 
    public void doOnFailure(Throwable caught) 
    { 
     NavigateToLoginEvent.fire(eventBus); 
    } 

    @SuppressWarnings("unchecked") 
    @Override 
    public void doOnSuccess(FetchLoggedInUserResult result) 
    { 
     if (result == null) 
     { 
      Log.info("doOnSuccess() 1 : LoggedInUser not found on server"); 
      NavigateToLoginEvent.fire(eventBus); 
     } 
     else 
     { 
      Log.info("doOnSuccess() 2 : LoggedInUser found on server"); 
      if (result.getLoggedInUser() != null) 
      { 

       currentUser = new CurrentUser(); 
       currentUser.setMerchantConsoleUser(result.getLoggedInUser()); 

       SessionFactory.getClientSessionInstance().put(SessionKeys.LOGGED_IN_USER, result.getLoggedInUser()); 

       PlaceRequest currentPlaceRequest = placeManager.getCurrentPlaceRequest(); 

       Log.info("doOnSuccess() 3 : " + currentPlaceRequest.getNameToken()); 

       if (currentPlaceRequest != null) 
       { 
        placeManager.revealPlace(currentPlaceRequest); 
       } 
      } 
      else 
      { 
       NavigateToLoginEvent.fire(eventBus); 
      } 
     } 
    } 
} 

}

在此先感謝。

+0

是否有可能發佈您的代碼片段?例如onReveal方法。 – David

+0

Dvd,根據要求添加代碼。你會注意到,這裏的重點是有權訪問頁面。我們正在爲刷新方案帶來併發症。除非需要,否則我沒有重寫演示者的任何onReveal()方法,所以在那裏不會有任何重要的東西。 – Bhavesh

+0

你的看門人是否有@singleton註解? – David

回答

1

謎底揭曉,添加以下代碼onBind()方法,並刷新瀏覽器開始在所有環境中工作的打算。這似乎是GateKeeper試圖從服務器獲取數據的框架模糊行爲,當時主持人的可見性被設置爲false,這同樣的想法讓我寫下面的代碼,它的工作,希望GWT-P的人可以看看在這個帖子想想適當的方式來處理這種情況:

/** 
    * This piece of code takes care of revealing page on browser refresh event. 
    * On browser refresh somehow visibility of page is set to false, so, we need to manually fire the reveal content event. 
    */ 
    if(this.getProxy().canReveal() == true && !this.isVisible()){ 
       revealInParent(); 
    }