Domanda

which combinations of Widget/Template and ClientBundleare allowed, and are there any known limitation / things you should consider when using them.

Afaik something like:

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

isn't allowed since it throws an error.

Something like

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

and use it with something like iconONLY(w.getElement()); is possible, but the Widget loses all functionality, because it's attache method isn't executed correctly.

To summ it up, I assume that Templates are not intended to have Widgets placed inside them!

ClientBundle are intended hold the content Widgets. Using them inside other elements e.g: like

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

called with iconONLYimageResource.getSafeUrl); can cause problems...

Are my assumptions correct? Please tell me if you tryed/ used one of the combination and how it worked?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top