在我的一个 GWT-Platform 应用程序中,我面临一个奇怪的问题,当我在 eclipse GWT 插件中配置的码头运行应用程序并点击浏览器刷新当前页面已成功加载(placeManager.getCurrentPlaceRequest())但当应用程序战争部署在tomcat/jboss 执行在当前位置请求的演示者的 onBind() 方法之后停止并且不显示页面。
在处理刷新的过程中,该 Presenter 的 GateKeeper 的第一次 canReveal() 方法返回 false,在服务器调用后我再次显示当前位置,这导致 canReveal() 方法返回 true,但 Presenter 仍然未显示。所以,在这里我怀疑有些棘手!
关于这种行为的任何提示?
以下是实现的 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);
}
}
}
}
}
提前致谢。