sof
sof

Reputation: 9649

Display GWT RPC result in a new window

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) {}
        });

Upvotes: 0

Views: 335

Answers (1)

jusio
jusio

Reputation: 9900

You will can use Javascript via JSNI to solve this problem.

Method like this does the trick:

public native void showWindowWithHtml(String html)/*-{
  var newWindow = $wnd.open("about:blank"); //receive a reference to the window object
  newWindow.document.body.innerHTML = html; //works for IE9 and Chrome 
  newWindow.onload = function(){newWindow.document.body.innerHTML = html} //works for Firefox 11

}-*/;

When you call, it a new window with specified HTML. Also not that js inside this native method is just an example, I don't guarantee that it will always work everywhere.

You'll have to use this approach since GWT doesn't have built-in support for working with external windows.

Upvotes: 1

Related Questions