我必须将扩展GWT复合的小部件附加到使用如下标记的自定义小部件:
<div class="left">
<div class="right">
<div class="content">{content}</div>
</div>
</div>我需要插入小部件嵌套的div与内容类。
下面我将发布我的自定义小部件的构造函数:
public class VideoPanel extends Component {
public VideoPanel(final Widget content,
final VideoPanelAppearance appearance, final int width,
final int height) {
this.content = content;
this.appearance = appearance;
final SafeHtmlBuilder sb = new SafeHtmlBuilder();
appearance.render(sb,
SafeHtmlUtils.fromTrustedString(content.toString()));
final XElement element = XDOM.create(sb.toSafeHtml());
final XElement contentElement = appearance.getContentElement(element);
contentElement
.setSize(getContentWidth(width), getContentHeight(height));
setElement(element);
setPixelSize(width, height);
}
}我不确定字符串:
SafeHtmlUtils.fromTrustedString(content.toString())内容是视频播放器小部件。并且上面的代码结果是EMBED-tag不会出现在HTML页面中。
发布于 2013-06-20 19:52:08
看起来您从未在代码中将内容小部件添加到contentElement中。从逻辑上讲,除非您的VideoPanelAppearance以某种方式与contentElement相关(从代码中看不出这一点),否则呈现不会将它们关联起来。为什么不将content元素作为“contentElement”的子元素添加:
/*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());我还会确保appearance.getContentElement( element )返回带有"content“类的预期元素。希望这能有所帮助。
发布于 2013-06-20 21:04:59
解决方案:
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());
}
}https://stackoverflow.com/questions/17146908
复制相似问题