GWT:在启动时执行初始RPC调用的最佳方式? [英] GWT : best way to do an initial RPC call at startup?

查看:123
本文介绍了GWT:在启动时执行初始RPC调用的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想检索在服务器端动态生成的配置数据,当用户加载页面时。但是如果我从浏览器进行异步RPC调用来检索数据,我有时在页面完全加载之前没有得到响应,导致页面无法访问该配置数据。 (例如没有Thread.sleep()函数)



谢谢




感谢@ Steve-J的回应,我找到了一个解决方案......

基本上这个想法如下:


  • 创建一个新的StartupCompleted事件

  • 开始onModuleLoad()

  • 中的初始RPC调用该RPC调用的onSucess方法在App Controller的go()方法结束时触发StartupCompleted事件

  • ,而不是将默认操作插入历史记录[ .newItem( 默认); ],或者如果通过书签[使用History.fireCurrentHistoryState();来调用当前的历史状态; ],在事件总线

  • 上为StartupCompleted事件注册一个处理程序,当StartupCompleted事件被触发时,不要做任何事情

  • 那时,在历史记录中插入默认操作或激活当前历史记录状态



...



最初的RPC调用是在完成其他任何事情之前完成的......



这种方法有什么问题吗?



请注意,正如@ Tom-Miette所建议的那样,直到收到StartupCompleted事件后,才会有一个简单的加载...消息。

您是否在控制流中使用消息传递?我进行RPC调用,并在成功时发送触发用户第一个活动弹出框的消息以进行交互。失败时,会触发不同的消息,触发弹出窗口告诉用户他无法继续。



不要忘记在弹出窗口中启用玻璃面板,以便用户在等待时不会在背景中弄乱任何东西。



更新: 来自评论:但我的问题是用户可以为页面添加书签,并直接转到它没有任何交互作用,我可能会遇到这种情况,即我没有收到RPC调用的结果,但是我在哪里生成了他所请求的页面,即使在那一代中,我尝试检查是否收到了结果,在完成页面生成之前,我无法停下来。



啊,我明白了。好的,GWT为此提供了一个解决方案。您应该查看活动和地点。当用户为页面添加书签时,他确实是为GWT应用程序的状态添加书签。当他回到那个页面时,Activity被触发并自动调用start()方法。这是您从服务器检索数据并执行所需的其他任何设置的机会。一旦你有了你的数据,你的start()方法继续设置所谓的视图。从用户的角度来看,页面已经加载了。

What is the best way to perform an initial RPC call at startup with GWT?

I would like to retrieve configuration data that are dynamically generated on the server side, when a user loads a page. but If I do an asynchronous RPC call from the browser to retrieve the data, I sometimes don't get a response before the page is fully loaded, resulting in the page not having access to that configuration data. (no Thread.sleep() function for example)

thanks


thanks to @Steve-J's response, I found a solution...

Basically the idea is the following:

  • create a new StartupCompleted event
  • start the initial RPC call in the onModuleLoad()
  • in the onSucess method of that RPC call, fire a StartupCompleted event
  • at the end of the go() method of the App Controller, instead of inserting the default action in the History [ with a History.newItem("default"); ], or to fire the current History state if called through a bookmark [ with a History.fireCurrentHistoryState(); ], don't do anything
  • register a handler for the new StartupCompleted event on the eventbus
  • when the StartupCompleted event is fired, catch it and at that time, insert the default action in the history or fire the current history state

et voila...

The initial RPC call is completed before doing anything else...

Is there anything wrong with that approach?

Note that as suggested by @Tom-Miette it is nice have a simple "loading..." message until the StartupCompleted event is received.

解决方案

Are you using messaging for control flow? I do the RPC call, and on success, I send the message that triggers the first active popup for the user to interact with. On failure, a different message is fired that triggers a popup to tell the user that he can't proceed.

Don't forget to enable the glass panel on your popups so that the user can't mess with anything in the background while he is waiting.

Update: From the comments: "But my problem is that the user can bookmark a page, and go directly to it without any interaction. I may end up in a case where I have not received the result of the RPC call, but where I am generating the page he has requested. Even if in that generation I try to check if I've received the result, I can't pause until that's the case before completing the generation of the page."

Ah, I see. OK, GWT has a solution for this. You should look at Activities and Places. When the user bookmarks a "page", he is really bookmarking the state of the GWT application. When he returns to that "page", the Activity is fired and automatically calls the start() method. This is your opportunity to retrieve data from a server and do any other setup that is required. Once you have your data, your start() method proceeds to set up what is called the "view". From the user's perspective, the "page" has "loaded".

这篇关于GWT:在启动时执行初始RPC调用的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆