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.