【问题标题】:How to embed links (anchor tag) into HTML context from UIBINDER in gwt如何在 gwt 中从 UIBINDER 将链接(锚标记)嵌入到 HTML 上下文中
【发布时间】:2012-07-03 21:59:21
【问题描述】:

我的 ui.xml 中有一个 HTML 小部件,我在 Uibinder 中使用它来填充数据,如下所示:

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 循环中完成的。 我的问题是如何为检索到的每个操作集在其中一个单元格(例如 operation id )上嵌入超链接或锚标记。我也希望有一个监听器。

附: - 它不允许我在 ui.xml 中使用 HTML 中的锚标记。

【问题讨论】:

    标签: html gwt hyperlink anchor uibinder


    【解决方案1】:

    您最好按照设计使用的方式使用这些工具:在 &lt;td&gt;@UiField Element foo + foo.setInnerHTML(toSafeString(...)) 上使用 ui:field="foo",而不是提取 HTML、修改它并重新注入它别处。您也可以使用&lt;g:Anchor&gt; 并附加@UiHandler 来处理ClickEvents。

    你使用 UiBinder 的方式让我想起了 SafeHtmlTemplates,或者新的 UiRenderer aka UiBinder for Cellshttps://developers.google.com/web-toolkit/doc/latest/DevGuideUiBinder#Rendering_HTML_for_Cells

    【讨论】:

    • 我想不出以你描述的方式使用 uibinder 的唯一原因是,我没有要设置的 parituclar 字段。如果您注意到我正在从数据库中检索一堆操作,并且我正在使用 HTML 模板在运行时填充它们。所以我不确定每个字段“foo”会存在多少这样的操作。
    • 我有什么更好的办法吗?
    • SafeHtmlTemplates 或 UiRenderer (2.5),和/或 CellList 或 CellTable。或者将其设为 Composite 小部件并为每个“操作”创建一个实例。
    • 我是 gwt 的初学者。你能指点我一些链接或一些代码 sn-p,因为我怎么能有多个使用 UIbinder 的复合小部件实例。我是否需要创建自己的小部件实现,然后将其导入 ui.xml?请分享你的专业知识..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-15
    • 2011-07-04
    • 2015-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多