开发者

Remote Object flex not working

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" 
               xm开发者_StackOverflowlns: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


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!
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜