Example name: Collection mapping with IWebORBArrayCollection (interface)
Description: Shows one way to tell WebORB to map a sever-side Array to a client-side ArrayCollection: by having the Array's class implement the interface IWebORBArrayCollection.
Prerequisites:
Client-side code: Browse  Download
Server-side code: Browse  Download
Feature availability:
  • WebORB for .NET Development Mode
  • WebORB for .NET Community Edition
  • WebORB for .NET Enterprise Edition
Run example:
Key points:
  • If your server-side class implements the IWebORBArrayCollection interface, then WebORB will serialize it to the client as an ArrayCollection.
  • In the server-side code, see:
    • Lines 133-153: Definition of the PersonnelRecordArrayCollection2 class as implementing IWebORBArrayCollection. IWebORBArrayCollection has no methods, so declaring it implementes it.
    • Lines 50-54: GetAllPersonnelRecordsAC2() returns a PersonnelRecordArrayCollection2.
    • Line 21: Definition of 'personnelAC2' as a PersonnelRecordArrayCollection2 initialized with the 'personnel' Array.
    • Lines 11-18: Definition of 'personnel' as a statically-initialized array of PersonnelRecord.
    • Line 5: using Weborb.Types, which declares WebORBArrayCollection.
  • In the client-side code, see:
    • main.mxml, line 38: calls GetAllPersonnelRecordsAC2().
    • main.mxml, lines 56-59: defines the DataGrid control. Note that it binds its dataprovider directly to the model's GetAllPersonnelRecordsAC2Result. It does not need to bind through an intermediary ArraCollection object, as the 'Binding data grid to array result' sample did. Why? Because in that sample, GetAllPersonnelRecordsAC2Result was just an Array, but in this sample, it's an ArrayCollection.
   
Things to try:
  • Compare and contrast the PersonnelRecordArrayCollection and PersonnelRecordArrayCollection2 classes. They are identical in every way, except in that the former is declared to subclass WebORBArrayCollection, and the latter is declared to implement IWebORBArrayCollection. Thee are two different ways of achieving the same objective: telling WebORB to serialize the server-side array to a client-side ArrayCollection.
  • Ask yourself: "Why would I choose to use the subclass WebORBArrayCollection approach? Why would I choose to use the implement IWebORBArrayCollection approach?"
See also:
Errata:
  • HumanResourcesServiceModel.as, line 19: WebORB's code generator did not generate the "import mx.collections.*" line; I had to add it, else the Flex compiler would not recognize the ArrayCollection type. Why didn't WebORB generate this import statement? A bug, apparently.