Problems with indepth flex loading of value objects (Lazy loading at the front-end?)
I'm using a java-backend with a flex frontend. And when i want to use a labelfunction it doesn't load the indepth properties suc开发者_C百科h as a value object, it's like it is lazy loaded in the flex side, I'm sure it is not comming from the backend because i've checked it overthere.
I've got it also in datagrid's that it doesn't load all the values at once.
for example
Class John{
var name:String;
var lastName:Doe;
}
Class Doe{
var lastName:String;
}
I ask at my back end get all John's, the backend gives me all John's which contains the Doe's. Now At the flex side I fire the result event from the callresponder when i receive that data. But still it can't acces the doe's into the Johns, the doe property of john is still null. When i ask it the second time it nows about the doe's, so it looks like lazy loading in a front-end way...
What am i doing wrong?
Greets
It's tricky to completely understand your question. However, I've had problems along these lines, many, many times. So I get the general problem.
One thing to remember with BlazeDS is that the classes sent over the network are serialized and deserialized. Meaning, in simplified terms, that the only things written and read over the network are the fields/properties of each class. You have to pay CLOSE attention to the basic data types in your classes on both the java side and the Flex side. Make sure all properties/fields and public getters/setters match and make sure they're clear.
What I mean by "clear" is, BlazeDS gets confused when it can't figure out which variables to stick where.
Although your Doe class is not a String, it only contains a string. So, when it's sent over the network, it looks just like a string. In cases like this, I've seen the blazeds get confused. It sees two strings come over the network and it can't figure out which goes where. To you, John contains "Doe" and a String but all BlazeDS really sees, in the end, is a String and a String.
Just to test, in your basic example, change Doe.lastName to an Integer or some other object. Chances are, it will stop coming up null on the other end. If it's still null, then your ActionScript and Java classes (John & Doe) don't match properly or they're too ambiguous.
The basic point is: when things come up null when you receive data, that means you have a problem with serialization. BlazeDS can't figure out how to read what was written to the network. So either adjust your fields, properties and public getters/setters.... or write your own method for serializing your objects.
This page describes blazeds serialization (and also how to handle it on your own) in GREAT detail:
http://livedocs.adobe.com/blazeds/1/blazeds_devguide/help.html?content=serialize_data_2.html
Once I fully understood this, I had far fewer errors of this kind.
Hope that helps,
-kg
Ok i still don't know why it did that, but i've solved it by using flat dto's, now i'm using a complete MVC architecture...
精彩评论