0

允许 Widget/Template 和 ClientBundle 的哪些组合,以及在使用它们时是否有任何已知的限制/您应该考虑的事情。

Afaik 类似:

@Template(""{0}\"<p>not allowed</p>")
SafeHtml iconONLY(Widget w);

不允许,因为它会引发错误。

就像是

@Template("{0}<p>not allowed</p>")
SafeHtml iconONLY(Element e);

并将它与类似的东西一起使用iconONLY(w.getElement());是可能的,但是 Widget 失去了所有功能,因为它的 attache 方法没有正确执行。

总而言之,我假设模板不打算在其中放置小部件!

ClientBundle 旨在保存内容小部件。在其他元素中使用它们,例如:喜欢

@Template("{0}<p>not allowed</p>")
SafeHtml iconONLY(SafeUrl safeurl);

调用iconONLYimageResource.getSafeUrl);可能会导致问题...

我的假设正确吗?请告诉我您是否尝试/使用过其中一种组合以及它是如何工作的?

4

1 回答 1

1

The first and the second ones makes sense that they don't work, since you are trying to insert just the element or widget into a string (SafeHtml is at the end of the day just a String) - of course the event wiring won't work. Widgets cant be cloned like that, there is more to them then just the element they are made of.

The last is an error because you are putting a Uri into the text content - you probably mean something like

@Template("<img src=\"{0}\" /><p>not allowed</p>")
SafeHtml iconONLY(SafeUri safeurl);

to display an image.

What are you trying to do? If trying to display an image, putting the SafeUri in an img tag is one option, another would be to put together a SafeHtml instance to insert:

@Template("{0}<p>not allowed<p>")
SafeHtml iconONLY(SafeHtml icon);

//...
AbstractImagePrototype proto = AbstractImagePrototype.create(icon);
SafeHtml iconHtml = SafeHtmlUtils.fromTrustedString(proto.getHTML());
template.iconONLY(iconHtml);

The basic idea of SafeHtml is that you build up strings of html instead of dom elements - this allows those strings to be reused, or to all be injected at once (which is usually faster than appending elements to the dom) - this is not how widgets are added to one another, and trying to manipulate widgets like this will just end up with missing pieces, as you've noticed.

于 2012-04-26T15:44:23.013 回答