Remote Object flex не работает - PullRequest
0 голосов
/ 08 февраля 2011

Я создаю приложение, используя Flex 4 + Spring Blazeds Integration 1.5 + Spring 3.0.5 + Hibernate, работающий на jboss-5.1.0.GA.Я создаю простую форму входа в систему, и когда отправить строку через удаленный объект, она работает нормально.Но когда попытка использовать объект, его просто не работает.Забавно, что это даже не показывает Alert, что пут!Кроме того, если я удаляю тег «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-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:

<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

Спасибо !!Andre

1 Ответ

0 голосов
/ 18 февраля 2011

с первого взгляда, ваша конфигурация bean и XML кажется правильной.

Я заметил в вашем файле MXML, что событие alertResult отсутствует, и, вероятно, именно поэтому bean не отображается наflex side!

попробуйте добавить его в свой файл MXML:

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

    Alert.show(userSistema.username, userSistema.password);
}
  • Я тоже бразилец!
...