【问题标题】:Mapping Java ArrayList<CustomClass> and Flex ArrayCollection映射 Java ArrayList<CustomClass> 和 Flex ArrayCollection
【发布时间】:2009-10-05 11:06:29
【问题描述】:

我目前正在尝试通过 LCDS 将 java ArrayList 与 Flex ArrayCollection 进行映射。 我的 Flex 应用程序确实调用了返回 ArrayList 的 Java 方法,但我还没有设法检索 ArrayList 以在 Flex 端的 DataGrid 中显示它。

Java 方面: 我有 2 节课: - Jco_test.java:它包含方法 public ArrayList all() - Customclass.java:它包含一个初始化一些变量的构造函数

    public class CustomClass {

    String airline;
    String cityFrom;
    String cityTo;
    Date flightDate;
    BigDecimal price;

    public CustomClass(String s1, String s2, String s3, Date d, BigDecimal bd){
        airline = s1;
        cityFrom = s2;
        cityTo = s3;
        flightDate = d;
        price = bd;
    }    
}

FlexSide:

  • test.mxml:

            import mx.messaging.AbstractConsumer;
            import mx.collections.ArrayCollection;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.controls.Alert;
    
        public var flightList:ArrayCollection;
    
        public function ResultHandler(event:ResultEvent):void{
            flightList = (event.result as ArrayCollection);             
        }
    
        public function FaultHandler(event:FaultEvent):void{
            flightList = new ArrayCollection();
            ta.text = "Error id: " + event.fault.errorID + "\n";
            ta.text += "String: " + event.fault.faultString + "\n";
            ta.text += "Code: " + event.fault.faultCode + "\n";
            ta.text += "Detail: " + event.fault.faultDetail + "\n";
            ta.text += "Stack: \n" + event.fault.getStackTrace() + "\n";
        }
    

RemoteObject id="ro" destination="jco" result="ResultHandler(event);" fault="FaultHandler(event);"

    <mx:Panel title="monTest" width="699" height="549" x="10">
        <mx:Button label="go" click="ro.all();"/>
        <mx:DataGrid dataProvider="flightList">
            <mx:columns>
                <mx:DataGridColumn dataField="AIRLINE" headerText="Airline" />
                <mx:DataGridColumn dataField="CITYFROM" headerText="From" />
                <mx:DataGridColumn dataField="CITYTO" headerText="To" />
                <mx:DataGridColumn dataField="FLIGHTDATE" headerText="Date" />
                <mx:DataGridColumn dataField="PRICE" headerText="Price" />
            </mx:columns>
        </mx:DataGrid>
        <mx:TextArea id="ta" width="100%" height="219"/>    
    </mx:Panel>
  • CustomClass.as:

    [Bindable]
    [RemoteClass(alias="utils.CustomClass")]
    public class CustomClass{
        public var airline:String;
        public var cityFrom:String;
        public var cityTo:String;
        public var flightDate:Date;
        public var price:String;       
    }    
    

我做错了吗? 我仍然有一些疑问......我的 ArrayList 没有标题。如何检索 DataGridColumn 中的数据?

感谢您提供的任何帮助。 问候。

(抱歉格式问题...)


我确实忘记了 getter 和 setter。 现在,我可以在服务器日志中看到我正在寻找的值。但是 Flex 仍然无法显示数据。

这是日志:

[LCDS]Adapter 'java-object' called 'com.alti.jco.jco_test.all(java.util.Arrays$A
rrayList (Collection size:0)
)'
[LCDS]Result: 'java.util.ArrayList (Collection size:3)
  [0] = utils.CustomClass
    cityTo = aa
    price = 30
    cityFrom = aa
    flightDate = Sun Jan 12 00:00:00 CET 1913
    airline = aa

  [1] = utils.CustomClass
    cityTo = bb
    price = 30
    cityFrom = bb
    flightDate = Sun Jan 12 00:00:00 CET 1913
    airline = bb

  [2] = utils.CustomClass
    cityTo = cc
    price = 30
    cityFrom = cc
    flightDate = Sun Jan 12 00:00:00 CET 1913
    airline = cc

'
[LCDS]Serializing AMF/HTTP response
Version: 3
  (Message #0 targetURI=/2/onResult, responseURI=)
    (Externalizable Object #0 'DSK')
      (Externalizable Object #1 'flex.messaging.io.ArrayCollection')
        (Array #2)
          [0] = (Typed Object #3 'utils.CustomClass')
            cityTo = "aa"
            price = "30"
            cityFrom = "aa"
            flightDate = Sun Jan 12 00:00:00 CET 1913
            airline = "aa"
          [1] = (Typed Object #5 'utils.CustomClass')
            cityTo = "bb"
            price = "30"
            cityFrom = "bb"
            flightDate = (Ref #4)
            airline = "bb"
          [2] = (Typed Object #6 'utils.CustomClass')
            cityTo = "cc"
            price = "30"
            cityFrom = "cc"
            flightDate = (Ref #4)
            airline = "cc"
1.254745294734E12
(Byte Array #7, Length 16)
(Byte Array #8, Length 16)
(Byte Array #9, Length 16)

我不确定 DataGridColumn 的数据字段是否区分大小写,所以我更改了数据字段以匹配每个字段。

【问题讨论】:

  • 数据字段中是否真的有大写字母,或者是拼写错误?
  • 请编辑帖子以更正代码格式。顺便说一句,dataField 是 AIRLINE 还是 airLine?
  • @bug-a-lot:我不确定数据字段是否区分大小写。我更改了大写字母,以便匹配 Java 类中的字段。 @Amarhogh:很抱歉格式化,但我在格式化我的代码时遇到问题......不知道为什么,有时我的文本只是不想格式化......我现在更改了数据字段,它现在是航空公司(比如java 和 actionscript 类)。

标签: java apache-flex arrays actionscript lcds


【解决方案1】:

1 次观察

在CustomClass.java中添加getter和setter

【讨论】:

    【解决方案2】:

    我解决了我的问题 =) 我有一个绑定错误。

    我的 dataGrid 使用“flightList”作为 dataProvider,但我没有将其定义为 Bindable 变量。

    非常感谢您的回答 =)

    【讨论】:

      猜你喜欢
      • 2012-01-27
      • 2012-04-03
      • 1970-01-01
      • 2013-11-15
      • 2011-04-18
      • 2012-08-14
      • 2011-12-25
      • 2012-07-15
      • 1970-01-01
      相关资源
      最近更新 更多