Search code examples
gwtuibinder

How to fill a UiRenderer with a safeHtml value?


I have the following UiRenderer (template renerer file: not widget binder), and my issue is with the field 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>

In fact desc containes HTML and when I pass the value to the UiRenderer all my html tags become uninterpreted by the browser, since they are escaped.

Trying to use with SafeHtml is not accepted (as an argument to ui:text)


Solution

  • Try to use <ui:safehtml from='{...}'/> in your uiRenderer template.

    <!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>