|
|
References between objects when sending over AMF channel
Hi,
I have a question regarding the messaging between a Flex frontend and a Spring backend.
Suppose I have got classes Foo and Bar:
Code:
public class Foo {public Bar bar;}
public class Bar {
}
Now I send an object of type Foo via an AMF-Channel to my Flex Frontend which maps the classes in the following way:
Code:
[Bindable]
[RemoteClass(alias=quot;Fooquot;)]
public class Foo
{public var bar:Bar;}
[Bindable]
[RemoteClass(alias=quot;Barquot;)]
public class Bar
{
}
The objects are sent via methods of a remoting destination for example:
Code:
public class RemotingDestination {private Bar bar;public Foo getFoo() {
Foo foo = new Foo();
this.bar = new Bar();
foo.bar = this.bar;
return foo;
}public Foo getBar() {
return this.bar;
}public Foo setFoo(Foo foo2) {
foo2.bar == this.bar; //????
}}
My question is what happens with the references when I send the objects.Is the bar reference send automatically to the frontend when I call getFoo()?
Does BlazeDS retrieve it automatically when I call foo.bar in the frontend?
Do I have to call getBar() before I can use foo.bar in the frontend?
And is the Bar reference in the backend kept when I call foo = getFoo() and setFoo(foo) (without calling getBar between) in the frontend (commented with quot;????quot;) ?
I tested these things and it seems that the references are not sent automatically and that they are not kept when calling getFoo setFoo, but perhaps someone has more experience with BlazeDS and can help me to understand the internals.
Yes, the references should be set in the resulting ActionScript object, as long as you are actually casting the result to an instance of Foo.
I noticed you've got an instance of Bar as a field in your RemotingDestination...perhaps you are just doing this in your test, but this is generally not a good idea if you are using Spring's default singleton scope, as such classes need to be thread-safe.
Hi,
thanks for your reply. Do you mean that the reference should be set if I just call getFoo() without sending Bar explicitly?
Yes, as long as on the client side you cast event.result to an instance of Foo.
Hi,
I am casting the instance but the reference is not set. Probably it is because in the quot;realquot; application I send a collection of Foo-Objects when calling getFoo().
Here is the code used in the frontend (adopted to the example above):
Code:
var rawResult:ArrayCollection = ((event as ResultEvent).result as ArrayCollection);
for(var i:int = 0;ilt;rawResult.length; i++)
{
var newFoo:Foo= Foo(rawResult.getItemAt(i));
modelLocator.allFoos.addItem(newFoo);
}
When I try to call .bar on one of the saved Foo-objects, the reference is null instead of the correct object.
Is the cast incorrect or did I miss something?
Hi,
I found out why the references were not set. I missed the setter methods in my Java classes. I thought that a getter would be enough for Flex to create the references in the frontend but both methods are needed (Java Bean Standard). |
|