1
我有GWT中的服務器端對象,我不能移動到客戶端(即:不是@GwtCompatible)。我想在頁面上使用它們。我可以使用gwt將它們呈現爲html併發送給客戶端?是否可以在GWT的服務器端渲染html?
我有GWT中的服務器端對象,我不能移動到客戶端(即:不是@GwtCompatible)。我想在頁面上使用它們。我可以使用gwt將它們呈現爲html併發送給客戶端?是否可以在GWT的服務器端渲染html?
那麼,你當然可以在服務器上構建一個HTML代碼片段,例如像這樣:
服務器端:
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;
}
}
客戶端:
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) {
// ...
}
});
但更好的解決方案可能是創建一個簡單的數據對象,複製您從非GwtCompatible需要的數據將其轉移到客戶端,然後照常使用它。