如何使用safeHtml值填充UiRenderer?

时间:2014-06-16 11:40:04

标签: gwt uibinder

我有以下UiRenderer(模板renerer文件:not widget binder),我的问题是使用字段desc

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder">
    <ui:with field='logo' type='java.lang.String' />
    <ui:with field='name' type='java.lang.String' />
    <ui:with field='desc' type='java.lang.String' />
    <ui:with field='prodCnt' type='java.lang.String' />
    <div class="shopMainCell">
        <div class="shopLogo">
            <img src='{logo}' />
        </div>
        <div class="shopProps">
        <div class="name">
            <ui:text from='{name}'></ui:text> 
        </div>
        <div class="desc">
            <ui:text from='{desc}'></ui:text> 
        </div>
        <div class="prodCnt">
            <ui:text from='{prodCnt}'></ui:text> 
        </div>
        </div>
    </div>
</ui:UiBinder>

实际上desc包含HTML,当我将值传递给UiRenderer时,我的所有html标记都会被浏览器解释,因为它们已被转义。

不接受尝试与SafeHtml一起使用(作为ui:text的参数)

1 个答案:

答案 0 :(得分:4)

尝试在<ui:safehtml from='{...}'/>模板中使用uiRenderer

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder">
    <ui:with field='logo' type='java.lang.String' />
    <ui:with field='name' type='java.lang.String' />
    <ui:with field='desc' type='com.google.gwt.safehtml.shared.SafeHtml' />
    <ui:with field='prodCnt' type='java.lang.String' />
    <div class="shopMainCell">
        <div class="shopLogo">
            <img src='{logo}' />
        </div>
        <div class="shopProps">
        <div class="name">
            <ui:text from='{name}'/>
        </div>
        <div class="desc">
            <ui:safehtml from='{desc}'/>
        </div>
        <div class="prodCnt">
            <ui:text from='{prodCnt}'/>
        </div>
        </div>
    </div>
</ui:UiBinder>