实施“请稍候”的提示 Flex 应用程序的控制

发布于 2024-07-09 17:18:56 字数 386 浏览 5 评论 0原文

对于调用 Web 服务等长时间运行的操作,为 Flex 应用程序创建“请等待”控件是一种聪明的方法。

我不是在问它的图形部分 - 只是“控制器”部分。 我应该如何触发它并隐藏它。 我计划只制作一个带有文本的简单画布。

例如:

  • 我可以以某种方式拦截所有 Web 服务调用 - 而不必为每个 Web 服务激活它,
  • 我应该如何将其添加到我的画布中。 是否应该将其作为顶级组件添加到“stage”中?
  • 如果需要太长时间,它是否应该有一个“取消”按钮来取消 Web 服务请求。 这听起来有点复杂,因为我什至不确定是否可以终止正在运行的异步 Web 请求?

仅供参考:这是针对报告应用程序的,因此需要长时间运行的查询

What would be a clever way to make a 'please wait' control for a Flex application for long running operations like calling a webservice.

I am not asking about the graphical portion of it - just the 'controller' part. How should I trigger it and hide it. I am planning to make just a simple canvas with text in.

For instance :

  • can I somehow intercept all web service calls - and not have to activate it for every web service
  • how should i add it to my canvas. should it be added to 'stage' as a top level component?
  • should it have a 'cancel' button to cancel the web service request if it takes too long. that sounds kind of complicated because I'm not even sure if I can terminate a running async web request?

FYI: This is for a reporting application so long running queries are to be expected

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南巷近海 2024-07-16 17:18:57

我过去这样做的一种方法是拥有一个全局整数,并根据运行的 Web 服务增加/减少该值。 当计数器为0时,我会隐藏加载文本,当它大于0时,我会显示加载文本。 这是它的简化版本:


<mx:Application>
    <mx:Script>
        [Bindable]public var ws_count:int = 0;
    </mx:Script>
    <mx:Label text = "loading..." visible="{ws_count > 0}" />
</mx:Application>


然后我有一个小帮助程序类来控制全局计数器:


package ws {
    import mx.core.Application;
    public class WSCounter {
        public static function sent():void {
            Application.application.ws_count += 1;
        }
        public static function receive():void {
            Application.application.ws_count -= 1;
        }
    }
}

然后所需要做的就是在调用 Web 服务时调用帮助程序函数...例如:


import ws.WSCounter;
import mx.rpc.http.HTTPService;

var srv:HTTPService = new HTTPService();
srv.url = "http://localhost/service.py";
srv.addEventListener(ResultEvent.RESULT,function(event:ResultEvent):void {
    WSCounter.receive();
});
srv.send();
WSCounter.sent();

我一直认为有是一个更好的方法来做到这一点,就像你说的有某种类型的钩子来检测服务是否正在运行......我期待这篇文章中的其他回复......

One way I have done it in the past is to have a global integer and increment / decrement the value based on the web services running. When the counter was 0, I would hide the loading text, when it was greater than 0, I would display the loading text. Here is a simplified version of it:


<mx:Application>
    <mx:Script>
        [Bindable]public var ws_count:int = 0;
    </mx:Script>
    <mx:Label text = "loading..." visible="{ws_count > 0}" />
</mx:Application>


I then had a little helper class to control the global counter:


package ws {
    import mx.core.Application;
    public class WSCounter {
        public static function sent():void {
            Application.application.ws_count += 1;
        }
        public static function receive():void {
            Application.application.ws_count -= 1;
        }
    }
}

Then all that needs to be done is to call the helper function when a web service is called...e.g:


import ws.WSCounter;
import mx.rpc.http.HTTPService;

var srv:HTTPService = new HTTPService();
srv.url = "http://localhost/service.py";
srv.addEventListener(ResultEvent.RESULT,function(event:ResultEvent):void {
    WSCounter.receive();
});
srv.send();
WSCounter.sent();

I always have thought there was a better way to do this, like you said have some type of hook to detect if a service is running...I'm looking forward to other responses in this post...

夜夜流光相皎洁 2024-07-16 17:18:57

如果您使用的是 Cairngorm 或类似的实现 MVC 的框架,最简单的方法是更新绑定到 UI 组件(即主 mxml 下的 titleWindow 或其他)可见属性的“全局”变量(通过 Singleton 对象)。 该变量将在execute()期间更新为true,并在到达结果或故障回调方法时更新为false。
您可以添加一个“取消”按钮,将变量重置为“false”,但这并不意味着服务器将停止异步调用。 我不知道如何停止它并防止它从已取消的方法调用返回数据。 快速浏览一下 ASDoc,remoteobject 确实有一个 disconnect() 方法,可以丢弃所有挂起的请求响应程序。 我不确定这是否是优雅/正确的方法
如果您不想为每个 Web 服务调用设置它,您可能需要使用自定义事件链(请参阅 http://www.herrodius.com/blog/80 的想法),这样如果您调用单个或多个服务,您只需设置一次。

If you are using a framework like Cairngorm or similar that implements MVC, the straightforward approach is to update a "global" variable (via a Singleton object) thats bound to UI Component's (ie. titleWindow under main mxml or whatever) visible attribute. the variable will be updated to true during execute() and false when it reaches result or fault callback methods.
You can add a "cancel" button that resets the variable to "false" but it doesnt mean the server will stop the async call. i dont know how to stop it and prevent it from returning a data from a cancelled method call. taking a quick look at the ASDoc, remoteobject does have a disconnect() method that discards all the pending request responders. im not sure if its the elegant/right way to do it
if you do not want to set it for every web service call, you might wanna use a custom event chaining (see http://www.herrodius.com/blog/80 for ideas) so that you only have to set it once if you are calling single or multiple services.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文