在我的一个GWT-Platform应用程序中,我面临一个奇怪的问题,当我在eclipse GWT插件中配置的jetty中运行应用程序并点击浏览器刷新当前页面成功加载(placeManager.getCurrentPlaceRequest())但是当应用程序战争时部署在tomcat / jboss执行中,在当前位置请求的演示者的onBind()方法之后停止并且不显示页面。
在处理刷新的过程中,第一次为该Presenter的GateKeeper的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);
}
}
}
}
}
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 :(得分:1)
神秘透露,在onBind()方法中添加了以下代码,浏览器刷新开始按预期在所有环境中工作。这似乎是一个模糊的行为框架,其中GateKeeper尝试从服务器获取数据,此时主持人的可见性被设置为假,这同样的想法导致我编写以下代码并且它起作用,希望来自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();
}