Display GWT RPC result in a new window

299 views
Skip to first unread message

fg

unread,
May 14, 2012, 5:04:00 AM5/14/12
to Google Web Toolkit
GWT Window#open method can be used to open a new browser window, but
it works towards a normal synchronous URL connection. How to display
the asynchronous result from the GWT RPC call in a new browser window
below?

myServiceAsync.getHtmlResult(new AsyncCallback<String>() {
@Override
public void onSuccess(String htmlResult) {

//how to display #htmlResult in a new browser window?

}
@Override
public void onFailure(Throwable caught) {}
});

Jens

unread,
May 14, 2012, 5:16:59 AM5/14/12
to google-we...@googlegroups.com
I would store the generated html page on the server and let the server send the correct URL to that generated html page to the client. Then you can do Window.open(<url of generated html page>).

-- J.

fg

unread,
May 14, 2012, 5:44:50 AM5/14/12
to Google Web Toolkit
Thanks a lot for the reply.

Although the workaround slightly derails the simplicity that GWT RPC
usually brings and adds extra server load due to generating temp html
pages, i'd probably agree on it before any better idea comes out.

Joseph Lust

unread,
May 16, 2012, 3:06:43 PM5/16/12
to google-we...@googlegroups.com
Working from memory, usually if you open a new window, the child retains a reference to its parent (opener). So, you can have it refer back to its parent and ask for content.

So, I think you could achieve this with:
  1. Do your async call
  2. Open a new window
  3. New window is blank URL and simple JS to ask parent for content (ask through a JSNI method to GWT)
  4. Return the request from (3) with the HTML returned from your async.
  5. Replace the content of the child window with the target HTML.
That should do it, but you could also find more elegant means too with server side efforts.

Sincerely,
Joseph

fg

unread,
May 20, 2012, 2:38:13 PM5/20/12
to Google Web Toolkit
Many thanks for the JSNI approach. Could you elaborate a little bit on
"more elegant means too with server side efforts."?


On May 16, 9:06 pm, Joseph Lust <lifeofl...@gmail.com> wrote:
> Working from memory, usually if you open a new window, the child retains a
> reference to its parent (opener). So, you can have it refer back to its
> parent <http://www.w3schools.com/jsref/prop_win_parent.asp> and ask for
> content.
>
> So, I think you could achieve this with:
>
>    1. Do your async call
>    2. Open a new window
>    3. New window is blank URL and simple JS to ask parent for content (ask
>    through a JSNI method to GWT)
>    4. Return the request from (3) with the HTML returned from your async.
>    5. Replace the content of the child window with the target HTML.

Joseph Lust

unread,
May 20, 2012, 10:28:57 PM5/20/12
to google-we...@googlegroups.com
By that I meant what Jens was suggesting.

  1. Make async call from GWT to render the HTML on server and return some unique id for that transaction.
  2. Open the new window with a URL including that unique id from (1). The server should return the HTML generated in (1) to that URL.
But, with either solution you're rendering your HTML server side. GWT is all about letting the browser client do this work for you, so you'll need to consider how you'll render it on the server without GWT (though it is possible to use GWT serverside, but complicated).


Sincerely,
Joseph
Reply all
Reply to author
Forward
0 new messages