PDA

View Full Version : Displaying details from a java collection


GM
05-14-2006, 04:16 PM
Hello,
I have a method that remotely calls a java method which returns a collection of hibernate objects. How can I pick a couple of fields from this collection and throw them into a list or a combo box without having to loop the collection? Also,
mscYear.addItem(res[i].getSchoolYear(),i); is throwing an error since I cannot directly call a java method like that.
Thanks
GM.
<remotecall name="populateMSCYearComboBox" funcname="getYearList" remotecontext="$once{canvas.eventMan}">
<method event="ondata" args="res">
Debug.write("return value:", res);
for (i = 0 ; i &lt; res.length ; i++)
{ Debug.write("return type:",typeof(res));
mscYear.addItem(res[i].getSchoolYear(),i);
}
</method>
</remotecall>

Azza
05-14-2006, 06:16 PM
Set a dataobject as a parameter to your remote call and access the data using xpath. Depending on how you have defined your wsdl as to what the structure of the xml will look like... Something like this is what you want
<soap name="yearListService" wsdl="...>
<dataset name="dsYearList"/>
...

<remotecall name="populateMSCYearComboBox" funcname="getYearList" dataobject="dsYearList" ...

<method event="ondata">
var dp = local:classroot.dsYearList.getPointer();
var yearCount = 0;
var schoolYear = null;

yearCount = dp.xpathQuery('/item/getYearListResponse/out/year/last()');
if(yearCount != null) {
for(var i = 1; i < yearCount; i++) {
xpath = '/item/getYearListResponse/out/year[' + i + ']/schoolYear';

schoolYear = dp.xpathQuery(xpath + '/@yearId');
}
...
</method>

GM
05-14-2006, 06:42 PM
Hi Azza,
Is there any way to directly loop thru the collection and display its contents? Why I am asking this is because the remote method returns to me a collection of hibernate objects and I want to use the get methods from those objects. I am not using SOAP or WSDL. It is a simple call to a middle layer method that ultimately calls hibernate layer and returns with a collection of objects. Can you please tell me the Laszlo syntax to call a method from a POJO in the collection?

mscYear.addItem(res[i].getSchoolYear(),i); //this is wrong but what is the correct way to call the method, getSchoolYear?

Azza
05-14-2006, 07:05 PM
I would read
http://www.openlaszlo.org/lps-latest/docs/guide/data.html
and
http://www.openlaszlo.org/lps-latest/docs/guide/rpc.html#d0e25229

GM
05-15-2006, 07:31 AM
So, I guess the only way to access the data in that collection is to serialize it into an XML?

Azza
05-15-2006, 04:00 PM
Yep. We use hibernate pojos, serialize them using xfire, and bind to the ui using soap. Works a treat!

GM
05-15-2006, 06:15 PM
It is a pity that you cannot directly use java collections to populate the UI widgets. Thanks for your help.