Sunday, August 16, 2009

"Protocols that RULE the FLEX world"

In the context of RIA, protocols that we need to get familiarized with are
1. REST - HTTP Object <mx:httpservice>
2. SOAP - WebServices Object WSDL <mx:webservices>
3. AMF - Remote Objects <mx:remoteobject>
4. XML Sockets (myXML = new XMLSocket;)

RIA's essentially reside on the client and communicate with the servers only to request and process data unlike normal web apps which are page-centric.

First is the widely used, REST(Responseful State Transfer) includes - HTTP(Hyper Text Transfer Protocol):
  • HTTP Service Component typically consumes XML responses.
  • They let you send HTTP GET, POST, HEAD, OPTIONS, PUT, TRACE, and DELETE requests and include data from HTTP responses in a Flex application.
  • Flex does not support mulitpart form POSTs.
  • The HTTPService's send() method makes the call to the JSP page.
  • The resultFormat property of the HTTPService component is set to object, so the data is sent back to the Flex application as a graph of ActionScript objects.
<mx:HTTPService id="srv" url="catalog.jsp"/> <mx:DataGrid dataProvider="{srv.lastResult.catalog.product}" width="100%" height="100%"/> <mx:Button label="Get Data" click="srv.send()"/>

For RemoteObjects:
The results of remote invocations are returned via events.
RemoteObject provides the result event for success or fault for failures.
  • To implement we must write the corresponding handler functions. Flex will call these methods, supplying an Event object as a parameter. It’s our responsibility to get the information from the event and act accordingly.
  • Explicitly mapping Action Script objects to Java objects and Serializaton of data
  • Converting data from Java to Action Script
<mx:RemoteObject id="srv" destination="product"/>
<mx:DataGrid dataProvider="{srv.getProducts.lastResult}" width="100%" height="100%"/>
<mx:Button label="Get Data" click="srv.getProducts()"/>


For more indepth information, please refer to Flex3 with Java.

No comments: