PDA

View Full Version : Wait for onSuccess() to load into RpcProxy?



econ
2 Jul 2010, 4:32 AM
The structure of my application does not allow me to reference a Model I am using for my TreePanel/RpcProxy, etcetera in both my client and server. This is creating problems.

I am currently doing it like this:


RpcProxy<ArrayList<TreeModel>> proxy = new RpcProxy<ArrayList<TreeModel>>()
{
@Override
protected void load(Object loadConfig, AsyncCallback<ArrayList<TreeModel>> callback)
{
service.getNextTreeNode((TreeModel) loadConfig);
}
};


The 'service' referenced above is simply a class that is adding a layer between the client and server. This class does the majority of the work because it extracts all the information needed from the model, calls the server with string parameters where the server will then query a database.

I'm having a lot of trouble at present as it appears to be fundamentally flawed. Here is some very pseudo-pseudo-pseudo code to explain what happens:



final ArrayList<Model> to hold models to return to RpcProxy.
final ArrayList<String> to hold the values I need to pass to the server (as, if you've not been following, the server can't see the Model, hence my mess)

method:

// find out information from model

// add all appropriate information the server needs and then add to the final ArrayList<String> mentioned above

if(treeServiceAsyncSvc == null)
treeServiceAsyncSvc = (TreeServiceAsync) GWT.create(TreeService.class);

AsyncCallback ....
onSuccess()
generate the new models and add to final ArrayList<Model> mentioned above
onFailure()
doNothing

call server

return models;



In case it's not obvious above, by the time the 'return models' happens, the AsyncCallback may have not returned yet, therefore return an empty ArrayList. I need a way for my class to:


analyse the model
construct string values to send to server
call the server
WAIT FOR CALLBACK ONSUCCESS()
THEN return to RpcProxy


From what I can see so far this isn't possible. Could someone PLEASE assist? Thank you ever so much!

sven
5 Jul 2010, 10:02 AM
What you want is not possible.

pass the callback that you get inside your load method to your servicelayer. Your servicelayer than has to call the callback with the provided data.


You need to understand how async structures work.

mwmcmullen
6 Jul 2010, 12:23 AM
What you want is not possible.

pass the callback that you get inside your load method to your servicelayer. Your servicelayer than has to call the callback with the provided data.


You need to understand how async structures work.

I was sure it was impossible as well however I figured it was worth a question anyway. The reason why I am asking this question is because my server cannot see the client class for some reason. You see, I am using Enunciate, software which allows interchangeable GUIs for web services, and it seems to throw me the following error when I reference my client.models.TreeModel class in the server:



[INFO] Problem assembling the enunciate app.

Embedded error: Class not found: TreeModel


I'm not entirely too sure what is wrong as all of the examples seem to reference the client model class as well. Therefore something is up but I do not know what. I assume it is Enunciate slipping up somewhere, therefore if you haven't dabbled with Enunciate before then I fully understand. Cheers for the help.

Note that I posted the original question - I was having account troubles!

sven
6 Jul 2010, 2:38 AM
Are you sure that his class is in your classpath on the serverside?

mwmcmullen
6 Jul 2010, 2:41 AM
Are you sure that his class is in your classpath on the serverside?

I'm not entirely sure. How would I check this? - just to make sure I'm not missing something!