Flex/BlazeDS - 每个函数调用的 resultHandler 而不是每个 RemoteObject?

发布于 2024-07-26 17:14:25 字数 906 浏览 5 评论 0原文

我按照教程获取一些 Flex 代码来调用 Java代码托管在 Tomcat 服务器上。

这就是我的 RemoteObject 和调用远程函数的 Button 的声明方式:

<mx:RemoteObject id="productService" destination="productJavaService" result="resultHandler(event)" fault="faultHandler(event)"/>
<mx:Button label="Get all Products" click="productService.getAllProducts()" /> 

这些是 resultHandler 和 failureHandler 函数的定义:

private function resultHandler(event:ResultEvent):void
{
    products = event.result as ArrayCollection;
}

private function faultHandler(event:FaultEvent):void
{
    Alert.show(event.fault.faultString);
}

对我来说,这个明显的问题是 resultHandler 与 RemoteObject 作为一个整体而不是单独的关联。功能。 如果我添加一个新函数,例如“getSingleProduct”,那么显然需要使用不同的 resultHandler。 如何在函数级别指定 resultHandler?

I've followed this tutorial to get some Flex code to call Java code hosted on a Tomcat server.

This is how my RemoteObject and the Button to call the remote function is declared:

<mx:RemoteObject id="productService" destination="productJavaService" result="resultHandler(event)" fault="faultHandler(event)"/>
<mx:Button label="Get all Products" click="productService.getAllProducts()" /> 

These are the definitions of the resultHandler and faultHandler functions:

private function resultHandler(event:ResultEvent):void
{
    products = event.result as ArrayCollection;
}

private function faultHandler(event:FaultEvent):void
{
    Alert.show(event.fault.faultString);
}

The obvious problem with this for me is that the resultHandler is associated with the RemoteObject as a whole rather than the individual function. If I add a new function such as "getSingleProduct" then obviously a different resultHandler will need to be used. How do I specify the resultHandler at function level?

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

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

发布评论

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

评论(2

自此以后,行同陌路 2024-08-02 17:14:25

您可以在 RemoteObject 下定义 method 属性,在您的情况下,它将是 getAllProducts(); 你可以这样做:

<mx:RemoteObject id="Server" destination="ServerDestination" fault="faultHandler(event)">
    <mx:method name="getAllProducts" result="getAllProductsHandler(event)"/>
    <mx:method name="getOneProduct" result="getOneProductHandler(event)"/>
</mx:RemoteObject>

You can define a method property under a RemoteObject, in your case, it would be getAllProducts(); You can do so like this:

<mx:RemoteObject id="Server" destination="ServerDestination" fault="faultHandler(event)">
    <mx:method name="getAllProducts" result="getAllProductsHandler(event)"/>
    <mx:method name="getOneProduct" result="getOneProductHandler(event)"/>
</mx:RemoteObject>
辞取 2024-08-02 17:14:25

只是想添加:如果有人想使用 actionscript 实现此目的,您可以通过将 Responder 添加到从服务调用返回的 AsyncToken 来使用 actionscript 来实现此目的:

var responder:Responder = new Responder(onGetOneProductResult, onGetOneProductFault);
var token:AsyncToken = Server.getOneProduct();
token.addResponder(responder);

private function onGetOneProductResult(event:ResultEvent):void {
    // event.result is the data you sent back from the server
    var result:Object = event.result;
}

private function onGetOneProductFault(event:FaultEvent):void {
    trace("onGetOneProductFault : "+event.fault.faultString);
}

Just wanted to add: in case anyone wants to achieve this with actionscript, you can do this with actionscript by adding a Responder to the AsyncToken returned from the service call:

var responder:Responder = new Responder(onGetOneProductResult, onGetOneProductFault);
var token:AsyncToken = Server.getOneProduct();
token.addResponder(responder);

private function onGetOneProductResult(event:ResultEvent):void {
    // event.result is the data you sent back from the server
    var result:Object = event.result;
}

private function onGetOneProductFault(event:FaultEvent):void {
    trace("onGetOneProductFault : "+event.fault.faultString);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文