Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using OutputRaw in Java Tapestry

I have a web application running Java Tapestry, with a lot of user-inputted content. The only formatting that users may input is linebreaks.

I call a text string from a database, and output it into a template. The string contains line breaks as /r, which I replace with < br >. However, these are filtered on output, so the text looks like b<br>text text b<br> text. I think I can use outputRaw or writeRaw to fix this, but I can't find any info for how to add outputRaw or writeRaw to a Tapestry class or template.

The class is:

 public String getText() {
    KMedium textmedium = getTextmedium();
    return (textmedium == null || textmedium.getTextcontent() == null) ? "" : textmedium.getTextcontent().replaceAll("\r", "<br>");
    }

The tml is:

<p class="categorytext" id="${currentCategory.id}">
${getText()}
</p>

Where would I add the raw output handling to have my line breaks display properly?

like image 276
Ila Avatar asked Aug 22 '13 10:08

Ila


1 Answers

To answer my own question, this is how to output the results of $getText() as raw html:

Change the tml from this:

<p class="categorytext" id="${currentCategory.id}">
${getText()}
</p>

To this:

<p class="categorytext" id="${currentCategory.id}">
<t:outputraw value="${getText()}"/>
</p>
like image 55
Ila Avatar answered Sep 19 '22 17:09

Ila