Question

I want to put a FlexTable into a CellTable, so in my String getValue() I created the FlexTable and returned ft.toString(), where ft is my FlexTable.

However, When I do table.addColumn(flex_table_string, "Header"), GWT does not render the HTML but rather leaves it as text

Please Help,

Thanks,

Mat

Was it helpful?

Solution

You should build a Cell that constructs the HTML table using the SafeHtmlBuilder rather than building a widget and getting its HTML representation (BTW, you shouldn't even use toString() to do that, but rather create, say, a SimplePanel, put the widget in it and then call getElement().getInnerHTML() on the parent panel).
There are two main reasons:

  • SafeHtmlBuilder will be faster (that's the whole point of CellTable vs. Grid or FlexTable)
  • you're breaking expectations: serializing a widget will lose all event handling.

That being said, what you're asking is indeed possible: use a Cell that uses the SafeHtmlBuilder's appendHtmlConstant method. Either make one, or, unlike the escape/unescape roundtrip suggested by Alex, use a TextCell but construct it with a custom SafeHtmlRenderer (extend AbstractSafehtmlRenderer for simplicity) that uses SafeHtmlUtils.fromTrustedString.

OTHER TIPS

You need to replace all the &lt; and &gt; with < and >.

protected void render(Context context, SafeHtml value, SafeHtmlBuilder sb) {
    String html = value.asString().replaceAll("&lt;", "<").replaceAll("&gt;", ">");
    sb.appendHtmlConstant(html);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top