DataCopier

(This tag must be placed inside an <EventHandlers> tag or a <MessageHandlers> tag)

The DataCopier tag allows you to save values into some object. A possible storage is the "data" object available while the sequence is running.

<DataCopier destination="data" destinationKey="someProperty" source="result" sourceKey="someProperty" />

The DataCopier tags is a handy tag to quickly copy values from a source into some storage. You can use the event handlers scope "data" as a temporary storage from where handlers that follow in the list can read values. You can also use some other external variable as the storage.

Attributes

source

The source attribute specifies where to get the data to copy from. It can be one of this options:

  • event
  • data
  • result
  • fault
  • lastReturn
  • message
  • scope
  • currentEvent (maybe the same or different from the event if the tag is placed inside a resultHandlers block, faultHandlers block or any handlers block other than EventHandlers and MessageHandlers.

or another object. If you wish to specify another object, you need to use bindings:

<DataCopier source="{myModel}" ... />

sourceKey

If you need a property from the source instead of the source itself, you need to specify this attribute.

destination

The destination attribute specifies where to place the data. It can be one of this options:

  • event
  • data
  • result

or another object.

<DataCopier destination="{myModel}" ... />

destinationKey

If you want to set the value of a property of the destination object, instead of the destination itself, you need to specify this attribute.

5 responses so far

  1. I noticed two references to DataSaver elements on this page. Was DataSaver an old name for DataCopier?

    Also, how would one use the scope and data attributes?

    How would I copy from a property called text from a custom event of type StatusBarEvent to an mx:Label's text property with id statusMsg? Here is my best guess:

    <EventHandlers type="{StatusBarEvent}">
    <DataCopier
    destination="statusMsg"
    destinationKey="text"
    source="event"
    sourceKey="text" />
    </EventHandlers>
  2. Hi Mike,
    You are right, that was the old name. Thanks for catching that.

    Regarding what you want to do, if you want to use an object that is not one of the pre-defined ones (event, result, etc), you need to use bindings to point to that object. Because of that, the event map needs to have access to that object, that is be defined within the event map, as opposed as in the view.

    Because having any kind of reference to the view would couple those two things, I would instead either use a property in a "manager" or use the Dispatcher + ResponseAnnouncer/ResponseHandler. If the view that dispatches the event is not the same as the one that needs to show the message, I would use a Listener tag in the view that wants to show the message or use a property in the manager (if that is shared data) + Injectors.
  3. Can we use DataCopier to share data between modules?
  4. Unfortunately, the DataCopier isn't type-safe, meaning it doesn't give you a compile-time error if the sourceKey or destinationKey do not exist and the source/target is not dynamic.
    What is the proper solution?
    Unsing the InlineInvoker would be nice, if I could write my single line assignment statement right in there, but it expects a function, unlike Flex event tags that accept any AS code.

    <EventHandlers type="myEvent">
    <InlineInvoker method="myModel.someProperty = event.someValue" />
    </EventHandlers>
  5. i have a collection of objects Contact.
    in a view, i select a Contact in my collection, and modify some properties.
    then, i want to update it to the the server.

    so, i put my Contact in an event (=> event.contact), and in a localEventMap, i call a remoteService to update this contact to the server.
    the server do his job and return me a new Contact updated => resultObject

    in my collection, i want to have resultObject taking the place of the old contact (this which was stored in event.contact)

    here is my code :

    <EventHandlers type="{ContactEvent.UPDATE_CONTACT}">
       <RemoteObjectInvoker
          instance="{ServiceProfilSingleton.instanceContactUserService}"
          method="update"
          arguments="{[event.contact]}"
          debug="false"
          concurrency="last">
          <resultHandlers>
             <InlineInvoker
                method="{contactManager.populateContact}"
                arguments="{[event.contact, resultObject]}"/>
          </resultHandlers>
          <faultHandlers>
             <InlineInvoker
                method="{contactManager.onFaultError}"
                arguments="{fault}"/>
          </faultHandlers>
       </RemoteObjectInvoker>      
    </EventHandlers>

    in contactManager.populateContact()
    i do : contact = resultObject;
    but it does nothing, because, i my collection i keep the old contact.

    how can i do this ?

Leave a response

If you need help or want to comment on something not related to this page, please post in the forums. Thanks!

Leave this field empty