2011-04-14 67 views

回答

3

那麼,你當然可以在服務器上構建一個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需要的數據將其轉移到客戶端,然後照常使用它。