Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Parsing data from java though RemoteObject

Avatar

Level 3
HI all

Due this forum I finnally got make my Flex application talk
to a Java method at the server through FDS/RemoteObject

Although I searched and didnt find how to parse data
retrieved from java to AS3.. I'm trying to show them in DataGrid
but its being hard.



Flex is really lacking good materials on the web :(



Some one can indicate a good online tutoriol about this???



THX!!!
14 Replies

Avatar

Level 2
Hi,



How are you trying to use the data on the client? Would you
show some more code?



Thanks.

Avatar

Level 3
Hi,

I want exemples about data treating, I don't have any code
because I dont know what to do.



Do you have an example.. or tutorial.. or something like
that?

thank you..

Avatar

Level 2
The best example I could find is in the language ref -
http://livedocs.macromedia.com/flex/2/langref/mx/rpc/remoting/mxml/RemoteObject.html.
It shows making the call as well as binding to its result. The key
is to get familiar with the structure of the object that is
returned. For this you could use describeType()(
http://livedocs.macromedia.com/flex/2/langref/flash/utils/package-detail.html).



You can also try
mx.utils.ObjectUtil.toString(ro.yourMethod.lastResult) to see what
the result format looks like.

Avatar

Level 3

quote:



<mx:RemoteObject id="RO" destination="MyRemoteObjectDest"

fault="Alert.show(event.fault.faultstring), 'Error'">



<mx:method name="GetQuote">

<mx:arguments>

<symbol>{stockSymbol.text}</symbol>

</mx:arguments>

</mx:method>

</mx:RemoteObject>



<mx:Panel title="RemoteObject Example" height="75%"
width="75%"

paddingTop="10" paddingBottom="10" paddingLeft="10"
paddingRight="10">



<mx:Label width="100%" color="blue"

text="Enter a stock symbol to obtain a quote."/>



<mx:TextInput id="stockSymbol" text="ADBE"/>

<mx:Button label="Get Quote"
click="RO.GetQuote.send()"/>



<mx:Text htmlText="Company:
{RO.GetQuote.lastResult.GetQuoteResult.StockQuote.Company}"/>

<mx:Text htmlText="Current price:
${RO.GetQuote.lastResult.GetQuoteResult.StockQuote.Price}"/>



</mx:Panel>





Thanks, but look at this code, in order to this structure
-> "RO.GetQuote.lastResult.GetQuoteResult.StockQuote.Price"
work, the result must be XML doesnt it? I am a little bit confused
on the understandind of the resulted object :(



Cheers

Avatar

Level 2
RemoteObject calls translate Java Arrays to AS
ArrayCollections of objects. Based on your orignal DBAdmin /
Traducao post the code could look something like this.





<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
>

<mx:Script>

<![CDATA[

import mx.collections.ArrayCollection;

import mx.controls.Alert;

import mx.rpc.events.ResultEvent;

import mx.rpc.events.FaultEvent;

import mx.utils.ObjectUtil;



[Bindable]

public var lista:ArrayCollection;



[Bindable]

public var currentRecord:*;



private function processaDados(event:ResultEvent):void{

lista = event.result as ArrayCollection;

}



private function processaDadosFault(event:FaultEvent):void{

Alert.show(ObjectUtil.toString(event.fault));

}

]]>

</mx:Script>



<mx:RemoteObject id="ro" destination="DataAccess">

<mx:method name="retornaDados"
result="processaDados(event)"
fault="processaDadosFault(event)"/>

</mx:RemoteObject>



<mx:Button click="ro.retornaDados()" />



<mx:Label id="theID" text="{currentRecord.id}" />

<mx:Label id="texto" text="{currentRecord.texto}" />

<mx:Label id="traducao" text="{currentRecord.traducao}"
/>



<mx:DataGrid id="dg" dataProvider="{lista}"
change="currentRecord = dg.selectedItem"/>



<!-- or -->



<mx:DataGrid
dataProvider="{ro.retornaDados.lastResult}">

<mx:columns>

<mx:DataGridColumn dataField="id" headerText="ID" />

<mx:DataGridColumn dataField="traducao"
headerText="Traducao" />

<mx:DataGridColumn dataField="texto" headerText="Texto"
/>

</mx:columns>

</mx:DataGrid>





<!-- <DebugComponent xmlns="qa.utils.*" /> -->

</mx:Application>

Avatar

Level 3
Good! At this time I can't test it but it really helped me to
clear my ideas.



Reading your example, I see that when the Client-App gets the
array from the server, "IT KNOWS HOW TO PULL OUT PRIMARY DATA TYPES
FROM TRADUCAO", am I right? I got confused because I could not
imagine how AS3 would treat the Traducao type since it was created
by me! And I got even more confused reading an article at Livedocs
about Class Mapping. It seemed to me that, in order to a
not-standard class (like mine) be understood by AS3, it would first
be mapped.



Thank you for your effort Ruggles

Avatar

Level 2
That is correct. Our serialization mechanism converts the
object into its basic types. If the class is unknown to the client
then a simple AS Object will be created with the data. If it is a
known type (ours or yours with a mapping) then we attempt to create
a client instance of the given type.



If you had a client-side type for Traducao you'd just add
this line to the top, make sure it gets linked in by using it
somewhere in your MXML and the deserialized result should use it.



package pdv {



[RemoteClass alias="pdv.Traducao"]

public class Traducao{



public var id:int;

public var texto:String;

public var traducao:String;



public function Traducao() {}

....

}

Avatar

Level 3
Lol... these new technologies are getting really tricky ah???



But my Traducao data class is based on GETTERS & SETTERS.
Does it know how to pull out primary data types even though??? How
will AS3 know what getter function to associate with a primary
variable? Or maybe the PRIVATE attribute is not respected by AS3
and it's content can be extracted...

Avatar

Level 2
Yes, it considers public getters and setters first, then
pubic properties. The example above worked for me when using your
Traducao class (although I short-circuited the DB code and just
created a bunch manually in DBAdmin.retornaDados.



for (int i=0; i<10; i++) {

list.add(new Traducao(i, "record" + i, "still" + i));

}

Avatar

Level 3
Good.

So it might have some algo to guess the getter method name
based on the variable name. Most of the cases it is simple getVar
but it is not a rule.



Thank you for your answer... I really appretiate it.

Avatar

Level 3
Ruggles.. When I tested the sample you provided me using my
Traducao class (tested other examples from myself too), the
application worked fine but the data wasnt retrieved from server
and I got no error.. my Firefox show a message in the bottom ->
"Receiving data from server localhost"

This message doesnt go away.. do you know what is happening?
thxx!!! :)

Avatar

Level 2
You can get more information by turning on logging on both
client and server. For the server, in server-config.xml you'd want
to add something like this to the logging section (make sure
level="Debug"):



<target class="flex.messaging.log.ConsoleTarget"
level="Debug" >

<properties>

<prefix>[Flex] </prefix>

<includeDate>true</includeDate>

<includeTime>true</includeTime>

<includeLevel>true</includeLevel>

<includeCategory>false</includeCategory>

</properties>

<filters>

<pattern>Endpoint.*</pattern>

<pattern>DataService.*</pattern>

<pattern>Service.*</pattern>



<pattern>Message.command.*</pattern>

<pattern>Message.data.*</pattern>

</filters>

</target>



This will add a lot of debugging info to the server console
so you can see the RO calls and responses. In the client app you
can add:



<mx:TraceTarget level="0"/>



This will trace the client side of the picture to your
flashlog.txt.

Avatar

Level 3
Thx man.. I'll try it right now.. do you think the problem
can be at the java side? will log let me know that?

Avatar

Level 2
I really don't know. But piecing together the logs should
give you a clearer picture of what is happening.