PDA

View Full Version : Using serialize() to pass dataset as an RPC string parameter


yoavl
10-25-2004, 06:00 PM
I wish to pass the stringified version of a dataset as an input parameter to a server-side Java class.

In my remote call, I am using something like:
<param value="${escape(canvas.options.serialize())}"/>

When I check the value of serialize() in the debugger it prints out fine with all the elements and data, however when I pass it to my Java object I get an empty dataset root element, without any children.

I have tried all sorts of tricks, but it's always the same result - empty root element.

Passing escaped hard-coded xml works fine.

Any idea?

Thanks...

pablo
10-28-2004, 08:59 AM
Hi yoavl,

Can you try the following?


<param>
<method name="getValue">
return escape(canvas.options.serialize())'
</method>
</param>


Out of curiosity, are you using a local or http dataset?

Thanks,
pablo

yoavl
10-29-2004, 07:49 AM
I am using an http dataset.
I found out the problem wasn't related to string escaping.
What actually happens is that if I pass the dataset to the remote object using the remotecall's <param> tag, then I get a root-only xml from serialize(), even though in the debugger it shows up correctly (before making the remote call).
I managed to work around this by using a script to calculate the serialized form and invoking my remote object with a proxy.
Seems like when using the <param> the dataset is being evaluated once and even after it's been updated the remotecall still sees the original version of the dataset (which is empty).
Can someone from laszlo verify this or suggest a solution?

pablo
10-29-2004, 09:29 AM
This is due to the way constraints work. A constraint is evaluated once during startup and then evaluated only when its dependencies change.

Here's an example:


<canvas>

<view name="example" layout="spacing: 5">

<attribute name="a" value="one" type="string" />

<method name="getVar">
return this.a;
</method>

<text text="${ parent.a }" />
<text text="${ parent.getVar() }" />

</view>

<view bgcolor="0xeaeaea" layout="axis: x; spacing: 5">

<edittext name="input" text="two"></edittext>
<button text="update">
<method event="onclick">
var t = parent.input.getText()
canvas.example.setAttribute('a', t);
</method>
</button>

</view>

<simplelayout spacing="10" />

</canvas>


The constraint in text


<text text="${ parent.getVar() }" />


gets evaluated once during startup, but since the LFC doesn't know what dependencies getVar() has, it doesn't know when to reevaluate the constraint. This is what's happening with


<param value="${escape(canvas.options.serialize())}"/>


In your case, value gets evaluated too early (i.e. before the dataset has any data) and that's why you don't see any data. This is why you need to use getValue(), which acts as a getter for <param>, instead of using a constraint.

Another way to look at it is that attributes that have constraints aren't evaluated when you access them. Instead, constraints place values in attributes whenever its dependencies change in value.

For more information, checkout the constraints chapter in the developers guide:

http://www.laszlosystems.com/lps-2.2/docs/guide/constraints.html

Hope this helps....

pablo

yoavl
10-29-2004, 01:21 PM
Thanks. It helped.