0

I'm using Parsley in my flex mobile project. I have multiple destination services but I can't find more resources on how to add another destination service to config.xml file. The file is as below:

<objects 
    xmlns="http://www.spicefactory.org/parsley"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.spicefactory.org/parsley 
        http://www.spicefactory.org/parsley/schema/2.4/parsley-core.xsd">


    <object type="mx.rpc.remoting.RemoteObject" id="genBUS">
        <property name="destination" value="genBUS"/>
        <property name="endpoint" value="http://localhost:8080/ClinASM/messagebroker/amf" />
    </object>
</object>

In the case when I create another

<object type="mx.rpc.remoting.RemoteObject" id="anotherBUS"></objects>

and do

[Inject(id='genBUS')]
public var genBUS:RemoteObject;

it complains that I have defined multiple remote objects. How does it work? How can I inject another destination service? That would be great to gain more knowledge about Parsley...

UPDATE: config.mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:Object 
    xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns="http://www.spicefactory.org/parsley">


    <Object id="genBUS" type="mx.rpc.remoting.RemoteObject">
        <Property name="destination" value="genBUS" />
        <Property name="endpoint" value="http://localhost:8080/ClinASM/messagebroker/amf" />
    </Object>

    <Object id="karBUS" type="mx.rpc.remoting.RemoteObject">
        <Property name="destination" value="karBUS" />
        <Property name="endpoint" value="http://localhost:8080/ClinASM/messagebroker/amf" />
    </Object>


</mx:Object> 
Zaur Guliyev
  • 4,254
  • 7
  • 28
  • 44
  • Looks like it's not picking up the 'id' metadata and is trying to inject by type instead of by ID. – RIAstar Mar 29 '12 at 10:51
  • Yes I know..but how to define here in config.xml multiple Remote Objects?! – Zaur Guliyev Mar 29 '12 at 11:05
  • Just like you did, so the only thing I can think of from the information I have, is that there might be a bug in the XML-based configuration with ID's. Try writing the same configuration as MXML and see what happens? On a side note: it's not very good practice to use ID-based injection (cf. [Parsley docs](http://www.spicefactory.org/parsley/docs/2.1/manual/) sections 4.4 and 4.5) – RIAstar Mar 29 '12 at 11:13
  • the same: Error: More than one object of type mx.rpc.remoting::RemoteObject was registered – Zaur Guliyev Mar 29 '12 at 11:33
  • I have updated post, and included config.mxml...And btw app give the above error before launching - on initializing... – Zaur Guliyev Mar 29 '12 at 11:35

1 Answers1

2

Injecting by ID is not considerer to be good practice because you create a name-based dependency. Change the name, or make a typo, and your application breaks and it's hard to debug that.

So as a general rule you should try to avoid it. The Parsley docs explain how to do this. I'll just add a simple example to show you how you'd use that technique with your multiple RemoteObjects.

<fx:Object xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:p="http://www.spicefactory.org/parsley">

<fx:Script>
    import path.to.service.GenBusDelegate;
    import path.to.service.KarBusDelegate;
</fx:Script>

<fx:Declarations>
    <fx:String id="gateway">http://localhost:8080/ClinASM/messagebroker/amf</fx:String>

    <s:RemoteObject id="genBus" destination="genBus" endpoint="{gateway}" />
    <s:RemoteObject id="karBus" destination="karBus" endpoint="{gateway}" />

    <p:Object type="{GenBusDelegate}">
        <p:ConstructorArgs>
            <p:ObjectRef idRef="genBus" />
        </p:ConstructorArgs>
    </p:Object>

    <p:Object type="{KarBusDelegate}">
        <p:ConstructorArgs>
            <p:ObjectRef idRef="karBus" />
        </p:ConstructorArgs>
    </p:Object>

</fx:Declarations>
</fx:Object>

or if you don't want to use constructor arguments:

    <p:Object type="{GenBusDelegate}">
        <Property name="remoteObject" idRef="genBus"/>
    </p:Object>
RIAstar
  • 11,912
  • 20
  • 37
  • Is path.to.service.GenBusDelegate something different that my auto-generated GenBUS service class?! if yes how suppose I create that class?! – Zaur Guliyev Mar 29 '12 at 12:57
  • cause, if I include tag inside it says no such parameter of GenBUS... note: GenBUS is my auto-generated GenBUS.as service class – Zaur Guliyev Mar 29 '12 at 13:20
  • @lbstr Yes, that `path.to.service.GenBusDelegate` is just an example. I didn't know there was an auto-generated class, and neither do I know which package it is in. So either you replace that `import` statement with the proper path to your GenBus class, or you discard the import and just write the entire path in the 'type' attribute: `` – RIAstar Mar 29 '12 at 14:59
  • Oh..the fault was mine! I tried to call the second remote object method in view's initialize method - where no objects is bounded yet...I changed it and now it works! Thanks for your time & help! – Zaur Guliyev Mar 31 '12 at 07:07