如何用GWT实现进度条?
在 GWT 应用程序中,我有一个运行服务器端并使用 rpc(GWT 调度程序)调用的长进程,我希望以显示消息和总进度的进度条向客户端提供反馈。 我的问题是如何从服务器动态恢复消息和进度?
我对任何解决方案感兴趣,
提前感谢您的帮助。
In a GWT application, I have a long process that runs server side and invoked using rpc(GWT dispatcher) and I want to have a feedback to the Client as a progress bar showing messages and the total progress.
My question is how to recover messages and the progress dynamically from the server?
I'm interested in any solution
thank you in advance for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
查看孵化器中的获取进度条。 这里是某人使用它的另一个示例。
更新
如果您想在客户端显示进度,您需要定期对服务器进行异步调用以获取进度值。换句话说,服务器需要在某处写入/存储其进度有多远。然后,客户端对服务器进行异步调用,服务器读取该值并将其发送回客户端,客户端可以更新进度条。
Have a look at the get progress bar in the incubator. Here is another example of someone using it.
UPDATE
If you want to display the progress on the client side, you will need to make async calls to the server periodically to fetch the progress value. In other words, the server needs to write / store somewhere how far it is with its progress. The client then makes an async call to the server, which reads that value and sends it back to the client, which can update the progress bar.
常规的异步调用应该可以做到这一点。但是您还需要从客户端实现某种轮询机制,以便它定期向服务器发送异步请求。
请参阅有关异步调用的教程
http://code.google.com/webtoolkit/doc/latest/tutorial /RPC.html
对于轮询机制,您应该能够通过简单的 while 循环来完成。在 while 循环内,继续调用 getStatus() 服务器调用,直到达到 100% 完成状态。
A regular Async call should do it. But you will also need to implement some sort of polling mechanism from the client side so that it will send an Async request to the server at periodic intervals.
See the tutorials on Async calls
http://code.google.com/webtoolkit/doc/latest/tutorial/RPC.html
For the polling mechanism, you should be able to do it with a simple while loop. Inside the while loop, keep calling the getStatus() server call till you get to 100% complete status.
或者您可以使用通道 API。它在 Python 和 Java 中都可用(可能还有其他受支持的叶猴)。 https://developers.google.com/appengine/docs/java/channel/
Or you can use the Channel API. It is available in both Python and Java (and probably the other supported langurs as well). https://developers.google.com/appengine/docs/java/channel/
查看进度同步器 和 进度条 来自 upload4gwt 可能会给你一些想法。
Taking a look at the progress syncer and progress bar from upload4gwt might give you some ideas.
http://www.java2s.com/Code/Java/GWT/GWTprogressbar.htm
您必须使用计时器定期轮询服务器,并将进度计算保留在服务器上。
http://www.java2s.com/Code/Java/GWT/GWTprogressbar.htm
You must use a timer to periodically poll the server, and keep the progress calculation on the server.