tags:

views:

47

answers:

1

I have this code in my gwt client side:

        String out = result.getConsoleOutput().replaceAll("\n", "<br/>");
        transOut.getElement().setInnerText(out);

Basically what comes out of consoleoutput() is text from a telnet client and transOut is a HTMLPanel in a UiBinder. I want it to show up pretty so I tried to change all the \n to html
, but when it shows up in firefox it looks like this on screen blah blah
blah blah...
. I am guessing gwt escapes the text somewhere how can I get it to write the real tag.

here is an image:

+4  A: 

You need to:

String out = result.getConsoleOutput().replaceAll("\n", "<br/>");
transOut.getElement().setInnerHTML(out);

Note the setInnerHTML() instead of setInnerText()

Cesar
Although setInnerHTML works, I would recommend NOT using it. Its an open invitation to XSS attacks if you are not careful in escaping user input. GWT provides several ways to dynamically create user interfaces; always prefer them over setInnerHTML()
sri