开发者

is it possible to render html in the server side in GWT?

i have se开发者_运维百科rver 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜