How to show a load screen during rpc call?

1,764 views
Skip to first unread message

crojay78

unread,
Jul 2, 2010, 12:02:21 PM7/2/10
to Google Web Toolkit
Hi,

I need to load a few things from my server after a user gives input.
Can somebody give an example how I can show a load screen as long as
the rpc is not finished? I structured the app in mvp style ... any
example would help me

Best regards

Thanks

andreas

unread,
Jul 2, 2010, 12:22:22 PM7/2/10
to Google Web Toolkit
You could show your load screen (for example a popup panel or even
just a label) right after issuing the RPC and hide it in onSuccess()
and onFailure().

Thomas Broyer

unread,
Jul 2, 2010, 8:23:58 PM7/2/10
to Google Web Toolkit


On 2 juil, 18:22, andreas <horst.andrea...@googlemail.com> wrote:
> You could show your load screen (for example a popup panel or even
> just a label) right after issuing the RPC and hide it in onSuccess()
> and onFailure().

And if you want the same panel to be shown in most cases, you could
bake it into a RpcRequestBuilder that you then inject inside you
RemoteService/Async, and that's it, nothing special to be done at the
"call site" of your service's method.

andreas

unread,
Jul 3, 2010, 3:45:17 PM7/3/10
to Google Web Toolkit
This sounds really great Thomas, haven't tried that yet.

Can this be done by subclassing RequestBuilder? And can I actually
really use my subclass of RequestBuilder as return type in
RemoteService methods? Would make me love the ability to use this
"return" feature of GWT RPC even more!

Thomas Broyer

unread,
Jul 3, 2010, 5:27:42 PM7/3/10
to Google Web Toolkit


On 3 juil, 21:45, andreas <horst.andrea...@googlemail.com> wrote:
> This sounds really great Thomas, haven't tried that yet.
>
> Can this be done by subclassing RequestBuilder? And can I actually
> really use my subclass of RequestBuilder as return type in
> RemoteService methods? Would make me love the ability to use this
> "return" feature of GWT RPC even more!

It's nothing to do with the return type of methods in your Async
interface. I'm talking about RpcRequestBuilder, not RequestBuilder:
http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/user/client/rpc/RpcRequestBuilder.html

(and yes, it allows you to use your subclass of RequestBuilder; but
IMO you'd rather show the popup in RpcRequestBuilder#doFinish (or
maybe even earlier, such as in doCreate()), and wrap the
RequestCallback in doSetCallback; but if you already have a
RequestBuilder-subclass, then just return it from doCreate)

Sebastian Rothbucher

unread,
Jul 4, 2010, 4:38:33 AM7/4/10
to Google Web Toolkit
Hi, what I'd to is:

1.) Display an image with some "loading..." animation
2.) Start the RPC asynchronously, e.g. like
tagDatabaseService.loadAllTagsForPerson(new TagQueryMessage(
tagQuery), new AsyncCallback<TagListMessage>() {

public void onSuccess(TagListMessage result) {
// HERE
3.) at the spot marked with //HERE, remove the image again and do
something with the result you obtained via RPC

Hope this helps...

Flori

unread,
Jul 4, 2010, 6:46:59 AM7/4/10
to Google Web Toolkit
Have a look at the following loading panel: http://www.sencha.com/examples/explorer.html
- you can find the explorer src and the loading image here:
http://www.sencha.com/products/gwt/download.php

Paul Schwarz

unread,
Jul 2, 2010, 4:52:05 PM7/2/10
to Google Web Toolkit
This doesn't answer your question directly but it should give you some
ideas:

public abstract class ActionCallback<ResultType> implements
AsyncCallback<ResultType> {

@Override
public final void onFailure(Throwable caught) {
BusyIcon.hide();
Window.alert("RPC Error: " + caught.getMessage());
handleFailure(caught);
}

@Override
public final void onSuccess(ResultType result) {
BusyIcon.hide();
handleSuccess(result);
}

/* Override to handle event failure result */
protected abstract void handleFailure(Throwable caught);

/* Override to handle event success result */
protected abstract void handleSuccess(ResultType result);

andreas

unread,
Jul 4, 2010, 9:25:55 AM7/4/10
to Google Web Toolkit
OK, I have not used RpcRequestBuilder yet and only used RequestBuilder
to alter the target of the request.

How exactly would you use RpcRequestBuilder to hide the panel? And
also from what I understood RpcRequestBuilder has nothing to do with
actually sending the request so displaying a panel on creation of the
request is kind of a short moment too early.

I think I'd stick to a combination of a subclass of RequestBuilder
where in send() the panel is shown and an implicitly assigned custom
abstract AsyncCallBack implementation where onSuccess()/onFailure
methods hide the panel and delegate the onSuccess()/onFailure() to a
subclass.

This of course depends on two things:
1) usage of return type in async service interface
2) possibility to use a subclass of RequestBuilder in async service
interface (not sure about that but I might give it a try)

Andreas

On 3 Jul., 23:27, Thomas Broyer <t.bro...@gmail.com> wrote:
> On 3 juil, 21:45, andreas <horst.andrea...@googlemail.com> wrote:
>
> > This sounds really great Thomas, haven't tried that yet.
>
> > Can this be done by subclassing RequestBuilder? And can I actually
> > really use my subclass of RequestBuilder as return type in
> > RemoteService methods? Would make me love the ability to use this
> > "return" feature of GWT RPC even more!
>
> It's nothing to do with the return type of methods in your Async
> interface. I'm talking about RpcRequestBuilder, not RequestBuilder:http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/g...

Thomas Broyer

unread,
Jul 4, 2010, 5:12:00 PM7/4/10
to Google Web Toolkit


On 4 juil, 15:25, andreas <horst.andrea...@googlemail.com> wrote:
> OK, I have not used RpcRequestBuilder yet and only used RequestBuilder
> to alter the target of the request.
>
> How exactly would you use RpcRequestBuilder to hide the panel? And
> also from what I understood RpcRequestBuilder has nothing to do with
> actually sending the request so displaying a panel on creation of the
> request is kind of a short moment too early.

Anyway, display will only be updated after your code is done
processing the event and yield to the browser, so doing it before the
"new RequestBuilder" or after the "request.send()" does change
anything (provided you don't yield to the browser in between).

> I think I'd stick to a combination of a subclass of RequestBuilder
> where in send() the panel is shown and an implicitly assigned custom
> abstract AsyncCallBack implementation where onSuccess()/onFailure
> methods hide the panel and delegate the onSuccess()/onFailure() to a
> subclass.

The advantage of RpcRequestBuilder#setCallback wrapping the
RequestCallback passed in argument, rather than an abstract
AsyncCallback, is that it doesn't change anything at the call site:
your don't have to remember to use the MyAsyncCallback abstract class.
Unless that's what you mean by "implicitly assigned custom
AsyncCallback".

> This of course depends on two things:
> 1) usage of return type in async service interface
> 2) possibility to use a subclass of RequestBuilder in async service
> interface (not sure about that but I might give it a try)

You'd have to provide your own RpcRequestBuilder, overriding
doCreate(), to use your own RequestBuilder subclass. Which means you
can have void or Request method return type, because GWT-RPC will call
send() itself on your subclass returned by doCreate.

Reply all
Reply to author
Forward
0 new messages