2011-02-08 95 views
0

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

我的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

谢谢! Andre

+1

您的services-config有一个硬编码的URL。您是否使用相同的URL(AKA Localhost?)提供SWF?您是否使用过ServiceCapture或Charles或Flash Builder网络监视器等程序来验证来回发送的内容? – JeffryHouser 2011-02-08 01:01:29

回答

0

一目了然,您的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); 
} 
  • 我是巴西人呢!