远程对象 Flex 不工作

发布于 2024-10-16 11:47:22 字数 4638 浏览 5 评论 0原文

我正在使用 Flex 4 + Spring Blazeds Integration 1.5 + Spring 3.0.5 + Hibernate 构建一个在 jboss-5.1.0.GA 上运行的应用程序。我创建了一个简单的登录表单,当通过远程对象提交字符串时,它工作正常。但是当尝试使用对象时,它的简单方法不起作用。有趣的是,它甚至不显示放置的警报!另外,如果我删除标签“RemoteClass”,它会发送到 java 但会发生错误。下面是代码和配置。

我的java类:

package com.controlefinanceiro.entities;

// imports 

@Entity
@Table(name="CF_USER_SISTEMA")
public class UserSistema implements Serializable{
    private static final long serialVersionUID = 1L;

    @Id
    @Column(name="USERNAME")
    private String username;

    @Column(name="PASSWORD")
    private String password;

    /**
     * Constructor
     */
    public UserSistema(){
    }

    // all getters and setters 
}

我的flex类:

package com.controlefinanceiro.view.model
{
    [Bindable]
    [RemoteClass=(alias="com.controlefinanceiro.entities.UserSistema")]
    public class UserSistema
    {
        public var username:String;
        public var password:String;
    }
}

服务配置:

<services-config>
    <services>
        <service-include file-path="remoting-config.xml" />
    </services>

    <!-- Spring factory registration -->
    <factories>
        <factory id="spring"
            class="com.controlefinanceiro.controller.SpringFactory" />
    </factories>

    <channels>
        <channel-definition id="channel-amf"
            class="mx.messaging.channels.AMFChannel">
            <endpoint
                url="http://localhost:8080/ControleFinanceiroServices/messagebroker/amf"
                class="flex.messaging.endpoints.AMFEndpoint" />
            <properties>
                <polling-enabled>false</polling-enabled>
            </properties>
        </channel-definition>
    </channels>

      // rest of config (log, redeploy)
</services-config>

远程配置:

    <adapters>
        <adapter-definition id="java-object"
            class="flex.messaging.services.remoting.adapters.JavaAdapter"
            default="true" />
    </adapters>

    <default-channels>
        <channel ref="channel-amf" />
    </default-channels>

    <destination id="loginService">
        <properties>
            <factory>spring</factory>
            <source>loginService</source>
        </properties>
    </destination>
</service>

Flex 应用程序:

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"  
                xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx"
               xmlns:comp="com.controlefinanceiro.view.componentes.*">
    <s:layout><s:BasicLayout/></s:layout>
    <fx:Declarations>
        <s:RemoteObject id="ro" destination="loginService" showBusyCursor="true" fault="onRemoteFault(event)"/>
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            public function doLogin(event:MouseEvent):void{
                Alert.show("login");
                var usu:UserSistema = new UserSistema();
                Alert.show("user");
                //usu.username = user.text;
                //usu.password = senha.text;
                //ro.doLogin.addEventListener(ResultEvent.RESULT,onLoginSuccess);
                //ro.doLogin.addEventListener(FaultEvent.FAULT,onLoginFault);
                //ro.doLogin(usu);
            }
            public function doEcho(event:MouseEvent):void{
                Alert.show("echo");
                ro.echo.addEventListener(ResultEvent.RESULT,alertResult);
                ro.echo.addEventListener(FaultEvent.FAULT,onLoginFault);
                ro.echo(user.text);
            }
            // others methods that just do an Alert.show()
        ]]>
    </fx:Script>
    <mx:Canvas width="242" height="141" horizontalCenter="0" verticalCenter="0">
        <s:Label id="msg" x="10" y="6"/>
        <s:Label x="21" y="37" text="Usuario:"/>
        <s:TextInput id="user" width="134" x="77" y="27"/>
        <s:Label x="30" y="67" text="Senha:"/>
        <s:TextInput id="senha" width="133" displayAsPassword="true" x="78" y="57"/>
        <s:Button label="Login" click="doLogin(event)" id="login" x="165" y="100"/>
        <s:Button x="113" y="100" label="Echo" click="doEcho(event)"/>
    </mx:Canvas>
</s:Application>

PS.:对于代码中糟糕的英语和“葡萄牙语”单词表示抱歉:P

谢谢! 安德烈

I'm building an application using Flex 4 + Spring Blazeds Integration 1.5 + Spring 3.0.5 + Hibernate running on jboss-5.1.0.GA. I create a simple login form, and when a submit a string via remote object it works fine. But when a try to use an Object its simple doesn't work. Funny is that it even don't shows the Alert that a put! Also, if I remove the tag "RemoteClass" it sends to java but an error occur. Bellow is the code and configs.

My java class:

package com.controlefinanceiro.entities;

// imports 

@Entity
@Table(name="CF_USER_SISTEMA")
public class UserSistema implements Serializable{
    private static final long serialVersionUID = 1L;

    @Id
    @Column(name="USERNAME")
    private String username;

    @Column(name="PASSWORD")
    private String password;

    /**
     * Constructor
     */
    public UserSistema(){
    }

    // all getters and setters 
}

My flex class:

package com.controlefinanceiro.view.model
{
    [Bindable]
    [RemoteClass=(alias="com.controlefinanceiro.entities.UserSistema")]
    public class UserSistema
    {
        public var username:String;
        public var password:String;
    }
}

services-config:

<services-config>
    <services>
        <service-include file-path="remoting-config.xml" />
    </services>

    <!-- Spring factory registration -->
    <factories>
        <factory id="spring"
            class="com.controlefinanceiro.controller.SpringFactory" />
    </factories>

    <channels>
        <channel-definition id="channel-amf"
            class="mx.messaging.channels.AMFChannel">
            <endpoint
                url="http://localhost:8080/ControleFinanceiroServices/messagebroker/amf"
                class="flex.messaging.endpoints.AMFEndpoint" />
            <properties>
                <polling-enabled>false</polling-enabled>
            </properties>
        </channel-definition>
    </channels>

      // rest of config (log, redeploy)
</services-config>

remoting-config:

    <adapters>
        <adapter-definition id="java-object"
            class="flex.messaging.services.remoting.adapters.JavaAdapter"
            default="true" />
    </adapters>

    <default-channels>
        <channel ref="channel-amf" />
    </default-channels>

    <destination id="loginService">
        <properties>
            <factory>spring</factory>
            <source>loginService</source>
        </properties>
    </destination>
</service>

Flex application:

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"  
                xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx"
               xmlns:comp="com.controlefinanceiro.view.componentes.*">
    <s:layout><s:BasicLayout/></s:layout>
    <fx:Declarations>
        <s:RemoteObject id="ro" destination="loginService" showBusyCursor="true" fault="onRemoteFault(event)"/>
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            public function doLogin(event:MouseEvent):void{
                Alert.show("login");
                var usu:UserSistema = new UserSistema();
                Alert.show("user");
                //usu.username = user.text;
                //usu.password = senha.text;
                //ro.doLogin.addEventListener(ResultEvent.RESULT,onLoginSuccess);
                //ro.doLogin.addEventListener(FaultEvent.FAULT,onLoginFault);
                //ro.doLogin(usu);
            }
            public function doEcho(event:MouseEvent):void{
                Alert.show("echo");
                ro.echo.addEventListener(ResultEvent.RESULT,alertResult);
                ro.echo.addEventListener(FaultEvent.FAULT,onLoginFault);
                ro.echo(user.text);
            }
            // others methods that just do an Alert.show()
        ]]>
    </fx:Script>
    <mx:Canvas width="242" height="141" horizontalCenter="0" verticalCenter="0">
        <s:Label id="msg" x="10" y="6"/>
        <s:Label x="21" y="37" text="Usuario:"/>
        <s:TextInput id="user" width="134" x="77" y="27"/>
        <s:Label x="30" y="67" text="Senha:"/>
        <s:TextInput id="senha" width="133" displayAsPassword="true" x="78" y="57"/>
        <s:Button label="Login" click="doLogin(event)" id="login" x="165" y="100"/>
        <s:Button x="113" y="100" label="Echo" click="doEcho(event)"/>
    </mx:Canvas>
</s:Application>

PS.: sorry for the poor english and the "portuguese" words in the code :P

Thanks!!
Andre

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

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

发布评论

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

评论(1

我纯我任性 2024-10-23 11:47:22

乍一看,您的 bean 和 XML 配置似乎是正确的。

我注意到您的 MXML 文件缺少alertResult 事件,这可能就是bean 没有显示在flex 侧的原因!

尝试将其添加到您的 MXML 文件中:

private function alertResult(event:ResultEvent):void
{
    userSistema:UserSistema = new UserSistema();
    userSistema = (UserSistema)event.result;

    Alert.show(userSistema.username, userSistema.password);
}
  • 我也是巴西人!

at a glance, your bean and XML configurations seems to be correct.

I noticed at your MXML file that the alertResult event is missing, and probably that´s why the bean isn´t shown at the flex side!

try adding it to you MXML file:

private function alertResult(event:ResultEvent):void
{
    userSistema:UserSistema = new UserSistema();
    userSistema = (UserSistema)event.result;

    Alert.show(userSistema.username, userSistema.password);
}
  • I am Brazilian too!
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文