2012-07-03 42 views
0

我在我的ui.xml我正在使用UiBinder的用於填充數據的HTML控件下面給出:如何嵌入鏈接(錨標記)到HTML中的上下文從UiBinder的GWT中

ui.xml - >

<g:HTML ui:field="operationsDetailTableTemplate" visible="false"> 
    <table class="{style.LAYOUT_STYLE}" width="100%" border="1"> 
     <tr> 
      <td><img src="images/indent-blue.gif"/></td> 
      <td> 
       <table class="{style.DEFAULT_STYLE}"> 
        <thead> 
          <tr> 
           <th>OperationUuid</th> 
                .... 
          </tr> 
        </thead> 
         <tbody> 
          <tr> 
           <td>%s</td> 
           ... 
          </tr> 
         </tbody> 
        </table> 
      </td> 
     </tr> 
     .... 
</g:html> 

Uibinder.java---> 

String htmlText = operationsDetailTableTemplate.getHTML() 
        .replaceFirst("%s", toSafeString(operation.getOperationUuid())) 
        .... 
HTML html = new HTML(htmlText); 
operationsDetail.add(html); 

以上是在for循環中爲從數據庫中檢索的每個操作完成的。 我的問題是,我可以如何嵌入一個超鏈接或錨點標記的單元格中的每一個(例如操作ID)爲檢索的每個操作集。我也希望有一位傾聽者。

P.S. - 它不允許我在ui.xml中的HTML中使用錨標籤。

回答

0

你最好使用工具,他們已經設計成可使用的方式:在<td>@UiField Element foo + foo.setInnerHTML(toSafeString(...))使用ui:field="foo",而不是提取HTML,修改它和其他地方回灌它。您也可以使用<g:Anchor>並附上@UiHandler來處理ClickEvent

你用UiBinder的方式讓我想起SafeHtmlTemplates,或新的UiRenderer又名UiBinder的用於細胞https://developers.google.com/web-toolkit/doc/latest/DevGuideUiBinder#Rendering_HTML_for_Cells

+0

我想不出u中描述的方式使用UiBinder的唯一原因是,我不有一個parituclar字段被設置。如果您注意到我正在從數據庫中檢索一堆操作,並且正在使用HTML模板在運行時填充它們。所以我不確定有多少這樣的操作會存在每個字段'foo'。 – dhavalp

+0

有沒有更好的辦法可以做到這一點? – dhavalp

+0

SafeHtmlTemplates或UiRenderer(2.5)和/或CellList或CellTable。或者讓它成爲一個Composite小部件,併爲每個「操作」創建一個實例。 –

相關問題