Reputation: 1336
I don't know if I'm trying to do something against the very nature of SafeHtmlBuilder. The thing is that I'd like to put html code (for instance, an < a > tag) in a div and make it safe. So here is my code:
SafeHtmlBuilder builder = new SafeHtmlBuilder();
builder.append(TEMPLATES.diagramHeader(
BasicConstants.diagramHeaderId + "description",
newBox.getDescription());
newDiv.setInnerHTML(builder.toSafeHtml().asString());
And my template:
@Template("<div id=\"{0}\">{1}</div>") /* Description */
SafeHtml diagramHeader(String idDesc, String description);
When getDescription() returns a string with html code (e.g., an < a > tag) and the contents of newDiv are rendered, I don't see the hyperlink, what I see is the HTML CODE of the hyperlink.
I would like to see the hyperlink, how can I do this? (I am willing to sacrifice HTML's safety for the cause).
Thanks!
Upvotes: 3
Views: 3664
Reputation: 64541
If the description
argument to the template can contain markup, then it should be of type SafeHtml
.
You'd then use SafeHtmlUtils.fromTrustedString(newBox.getDescription())
, as you're trusting newBox.getDescription()
to be safe.
As a side note, I don't understand why:
SafeHtmlBuilder
to append()
only oncesetInnerHTML
instead of setInnerSafeHtml
(maybe you're not using GWT 2.5?)Upvotes: 4