tags:

views:

60

answers:

2

I have a GWT page with a listing (from the datastore) on it. I understand how I can get this listing after the page is loaded, with an async call, but I want to make sure that when the page is loaded initially, it has valid data in it. Otherwise, the page loads most of the way, and then the listing is filled in, which leads to a choppy load, and a longer time the user needs to wait before the page loads.

So, how can I get data from the server into the page when it loads? Is there a way to call the server-side service from the constructor of my UIBinder class? I can't call the actual service implementation, since the client-side code can't reference the server-side code, right?

Surely this can't be a unique need, but I can't seem to find any tips on Google (though I might not be searching the right terms).

A: 

You could hide your whole page content until the data is loaded to avoid the choppy effect.

But the most user friendly way would be to display a loading message on your page load. Then in the success and failed events of your async call, after the data is bind, hide the loading message.

DrDro
One of the things I am trying to avoid is the delay in page loading. It seems that there is no need to make an async call immediately after loading the page, since the data should be available as the page loads.
pkaeding
+1  A: 

What I've done in my own project to solve the same problem is to use JSP to embed the data that I need into the page source as javascript objects. That way the data is already there by the time onModuleLoad() is called. Google have a bit of documentation on how to read javascript objects into your java code.

Obviously you'll need to know a little bit about jsp as well.

hambend
This looks very promising; thanks!
pkaeding
I would suggest using the `Dictionary` class, which can read simple JSON maps which get written to the page on page load. http://google-web-toolkit.googlecode.com/svn/javadoc/2.1/com/google/gwt/i18n/client/Dictionary.html -- very useful for this kind of thing.
Jason Hall
Good point. `Dictionary` will work fine and probably save you some lines of code. It's not as powerful as using JSNI overlays, though. You need to parse numeric and boolean values yourself, and more importantly it has no support for arrays. What you should use depends on the information you're embedding.
hambend
Thanks, JSNI was the ticket! I needed to load arrays, so I didn't go the `Dictionary` approach, but I will keep that in mind for the future.
pkaeding