我目前正在嘗試通過LCDS將Flex ArrayCollection與Java ArrayList進行映射。 我的Flex應用程序確實會調用返回ArrayList的Java方法,但我沒有設法檢索ArrayList以在Flex側將其顯示在DataGrid中。映射Java ArrayList <CustomClass>和Flex ArrayCollection
JavaSide: 我有2類: - Jco_test.java:它包含了方法public ArrayList的所有() - 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);」故障= 「FaultHandler(事件);」
<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中有大寫字母,還是他們是拼寫錯誤? – 2009-10-05 11:11:49
請修改帖子以糾正代碼格式。順便說一下,dataField是AIRLINE還是airLine? – Amarghosh 2009-10-05 11:25:59
@ bug-a-lot:我不確定數據字段是否區分大小寫。我改變了大小寫,以便匹配我的Java類中的字段。 @Amarghogh:抱歉格式化,但我有問題格式化我的代碼...不知道爲什麼,有時,我的文本只是不想格式化... 我現在更改了dataField,現在是航空公司(比如在java和actionscript類中)。 – 2009-10-05 13:12:41