1

i have server side objects in GWT that I cannot move to client (ie: not @GwtCompatible). I want to use them on a page. can I render them to html using gwt and send it to the client?

1 Answer 1

4

Well, you certainly could build an HTML snippet on the server, e.g. like this:

Server side:

public class MyServiceImpl extends RemoteServiceServlet implements MyService {

  public String getHtmlSnippet(String param) {

    String html = buildHtmlSnippetInASafeWay(param); // Use any (safe) HTML
                                                     // builder you like. (this
                                                     // is not GWT related!)
    return html;
  }
}

Client side:

myService.getHtmlSnippet(myParam, new AsyncCallback<String>() {

  @Override
  public void onSuccess(String result) {
    myParent.add(new HTML(result));
    // or: myElem.setInnerHTML(result);
  }

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

But the better solution is probably to create a simple data object, copy the data you need from your non-GwtCompatible class into that object, transfer it to the client, and use it there as usual.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.