Reputation: 15365
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?
Upvotes: 1
Views: 1097
Reputation: 37778
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.
Upvotes: 4