如何将GWT小部件附加到元素

如何将GWT小部件附加到元素,gwt,gxt,appearance,Gwt,Gxt,Appearance,我必须将扩展GWT组合的小部件附加到使用如下标记的自定义小部件: <div class="left"> <div class="right"> <div class="content">{content}</div> </div> </div> 在字符串中我不确定: SafeHtmlUtils.fromTrustedString(content.toString()) 内容是视频播放器小部件。上述代码导致

我必须将扩展GWT组合的小部件附加到使用如下标记的自定义小部件:

<div class="left">
  <div class="right">
    <div class="content">{content}</div>
  </div>
</div>
在字符串中我不确定:

SafeHtmlUtils.fromTrustedString(content.toString())

内容是视频播放器小部件。上述代码导致嵌入标记不会出现在HTML页面中。

看起来您从未将内容小部件添加到代码中的contentElement中。从逻辑上讲,除非您的VideoPanelAppearance与contentElement(代码中没有明显的内容)存在某种关联,否则渲染不会将它们关联起来。为什么不将content元素作为“contentElement”的子元素追加:

我还要确保appearance.getContentElement(element)返回类为“content”的预期元素。希望这有帮助。

解决方案:

public class VideoPanel extends Panel {

public VideoPanel(final Composite content, final VideoPanelAppearance appearance, final int width,
        final int height) {
    this.content = content;
    this.appearance = appearance;
    final SafeHtmlBuilder sb = new SafeHtmlBuilder();
    appearance.render(sb, title);
    setElement(XDOM.create(sb.toSafeHtml()));

    DOM.appendChild(getContainerElement(), content.getElement());
    adopt(content);
    getContainerElement().<XElement> cast().setSize(getContentWidth(width),
            getContentHeight(height));
    setPixelSize(width, height);
    sinkEvents(Event.ONCLICK);
}

public Element getContainerElement() {
    return appearance.getContentElement(getElement().<XElement> cast());
}

}
公共类视频面板扩展面板{
公共视频面板(最终合成内容、最终视频面板外观、最终内部宽度、,
最终整数高度){
this.content=内容;
这个外观=外观;
最终安全HTMLBuilder sb=新的安全HTMLBuilder();
呈现(某人、头衔);
setElement(XDOM.create(sb.toSafeHtml());
appendChild(getContainerElement(),content.getElement());
采纳(内容);
getContainerElement().cast().setSize(getContentWidth(width),
getContentHeight(高度));
设置像素大小(宽度、高度);
sinkEvents(Event.ONCLICK);
}
公共元素getContainerElement(){
返回外观.getContentElement(getElement().cast());
}
}
/*this will relate them via the DOM (so the widgets wouldn't know about it but
but in your case it doesn't seem like it matters*/
contentElement.appendChild(content.getElement());
public class VideoPanel extends Panel {

public VideoPanel(final Composite content, final VideoPanelAppearance appearance, final int width,
        final int height) {
    this.content = content;
    this.appearance = appearance;
    final SafeHtmlBuilder sb = new SafeHtmlBuilder();
    appearance.render(sb, title);
    setElement(XDOM.create(sb.toSafeHtml()));

    DOM.appendChild(getContainerElement(), content.getElement());
    adopt(content);
    getContainerElement().<XElement> cast().setSize(getContentWidth(width),
            getContentHeight(height));
    setPixelSize(width, height);
    sinkEvents(Event.ONCLICK);
}

public Element getContainerElement() {
    return appearance.getContentElement(getElement().<XElement> cast());
}

}