映射 Java ArrayList和 Flex ArrayCollection

发布于 2024-08-06 22:08:55 字数 4355 浏览 6 评论 0原文

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

Java端: 我有两节课: - 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:

     导入 mx.messaging.AbstractConsumer;
            导入 mx.collections.ArrayCollection;
            导入 mx.rpc.events.FaultEvent;
            导入 mx.rpc.events.ResultEvent;
            导入 mx.controls.Alert;
    
        公共 var FlightList:ArrayCollection;
    
        公共函数 ResultHandler(事件:ResultEvent):void{
            FlightList = (event.result as ArrayCollection);             
        }
    
        公共函数FaultHandler(事件:FaultEvent):void {
            飞行列表 = 新的 ArrayCollection();
            ta.text = "错误ID:" + event.fault.errorID + "\n";
            ta.text += "字符串:" + event.fault.faultString + "\n";
            ta.text += "代码:" + event.fault.faultCode + "\n";
            ta.text += "详细信息:" + event.fault.faultDetail + "\n";
            ta.text += "堆栈:\n" + event.fault.getStackTrace() + "\n";
        }
    

RemoteObject id =“ro”目的地=“jco”结果=“ResultHandler(事件);”故障=“故障处理程序(事件);”

    <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>
  • 自定义类.as:

    <前><代码>[可绑定] [RemoteClass(别名=“utils.CustomClass”)] 公共类自定义类{ 公共 var 航空公司:字符串; 公共 var cityFrom:String; 公共 var cityTo: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 的数据字段是否区分大小写,因此我更改了数据字段以匹配每个字段。

I'm currently trying to map a java ArrayList with a Flex ArrayCollection, through LCDS.
My Flex application does call the Java method that returns the ArrayList, but I haven't managed to retrieve the ArrayList to display it in a DataGrid, on Flex side.

JavaSide:
I have 2 classes:
- Jco_test.java: it contains the method public ArrayList all()
- Customclass.java: it contains a constructor that initializes some variables

    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;       
    }    
    

Am I doing something wrong?
I still have some doubts... My ArrayList does not have headers. How can I retrieve the data in my DataGridColumn?

Thanks for any help you can provide.
Regards.

(Sorry about the formatting issues...)


I had indeed forgotten the getter and the setters.
Now, I can see in the server log the values I was looking for. But Flex is still not able to display the Data.

Here is the log:

[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)

I'm not sure about the DataGridColumn's datafield case sensitivity, so I changed the datafields to match each field.

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

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

发布评论

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

评论(2

蹲墙角沉默 2024-08-13 22:08:55

1 观察

在CustomClass.java中添加getter和setter

1 observation

add getter and setter in CustomClass.java

琉璃梦幻 2024-08-13 22:08:55

我解决了我的问题 =)
我犯了一个具有约束力的错误。

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

非常感谢您的回答=)

I resolved my issues =)
I had a binding mistake.

My dataGrid was using "flightList" as the dataProvider, but I did not define it as a Bindable variable.

Thanks a lot for your answers =)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文