gpt4 book ai didi

java - GWT 平台 : onReveal() method is not invoked on browser refresh when application is deployed on tomcat/jboss

转载 作者:搜寻专家 更新时间:2023-11-01 03:41:52 33 4
gpt4 key购买 nike

在我的一个 GWT 平台应用程序中,我遇到了一个奇怪的问题,当我在 eclipse GWT 插件中配置的 jetty 中运行应用程序并点击浏览器刷新当前页面已成功加载(placeManager.getCurrentPlaceRequest())但是当应用程序 war 时部署在tomcat/jboss中,在当前位置请求的presenter的onBind()方法后停止执行,不显示页面。

在处理刷新的过程中,GateKeeper 的第一次 canReveal() 方法为该 Presenter 返回 false,在服务器调用后我再次显示当前位置,这导致 canReveal() 方法返回 true 但 presenter 仍未显示。所以,我怀疑这里有些棘手!!

有任何关于此类行为的提示吗?

以下是实现LoggedInGatekeeper的代码片段,其中起到关键作用:


public class LoggedInGatekeeper implements Gatekeeper
{



<pre><code>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);
}
}
}
}
</code></pre>

<p>}</p>

提前致谢。

最佳答案

谜底揭晓,在 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();
}

关于java - GWT 平台 : onReveal() method is not invoked on browser refresh when application is deployed on tomcat/jboss,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12490427/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com