Download Adobe LiveCycle Data Services ES from:
http://www.adobe.com/products/livecycle/dataservices/Install it for J2EE and not for integrated JRun. We will be using the express version. Alternatively you could use BlazeDS. To see the differences between the two visit this link:
Differences between Flex Data Services Express and BlazeDS
Please remember that using either means that you will have to buy it at some stage for commercial applications. See the respective licence for details. That being said these services are extremely useful and without them Flex looses a lot of utility.
You have set up the stage to use Remote Object.
Now, copy the java class you intend to use in the appropriate directory under WEB-INF/classes. Lets say we have a class file from your compiled java file called MyRemoteObj.class made from this file:
package app;
public class MyRemoteObj{
public String getMessage(){ return "hello"; }
}
Browse to WEB-INF/flex and open remoting-config.xml. Make sure it looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<service id="remoting-service" class="flex.messaging.services.RemotingService">
<adapters> <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
</adapters>
<default-channels>
<channel ref="my-amf"/>
</default-channels>
<destination id="responder">
<properties>
<source>app.MyRemoteObj</source>
<scope>application</scope>
</properties>
</destination>
</service>
Remember this xml file is just one of the files uploaded by services-config.xml. It just helps in breaking our config xml into usable parts. <adapters> define the backend object. <channels> are defined in service-config. Here we just specify the channel we intend to use. destination is the part that helps flex use the remote object. id is ised to refer to it. source is its location under the WEB-INF/classes directory.
Declare your remoter object in the MXML as
<mx:RemoteObject id="remoteObjRef" destination="responder" fault="handleFault(event)" result="handelResult(event)"/>
Use the id in AS to call the methods directly on the object: remoteObjRef.getMessage();
No comments:
Post a Comment