Simply Craig
Simply Craig

Reputation: 1114

Trying to add new line characters while using JSF h:outputText and Managed Beans

I have a h:outputText here

<h:outputText id="properties" value="#myBean.output}" />

Then I have a button that calls a function that updates the value in "output" which is a String that holds essentially a text document in it (That being multiple lines)

<h:panelGrid columns="2" >
    <p:outputLabel value="Display Output."/>
    <p:commandButton value="submit" action="#{myBean.updateOutput}">
        <f:ajax render="properties" />
    </p:commandButton>                  
</h:panelGrid>

However, I want it to have \n or some equivalent in output.

This is an example of what I would return:

Line1\nLine2\nLine3

However this just prints to the screen like this:

Text1 Text2 Text3

Changing it to br/ it doesn't do anything but cause it to put the literal text br/ instead of the white spaces above.

I am new to JSF and I just can't figure it out. I did search for an answer but none worked for me. I would really appreciate some help.

Upvotes: 2

Views: 3036

Answers (1)

Kishor Prakash
Kishor Prakash

Reputation: 8151

Set escape attribute on h:outputText to false.

Escape is Flag indicating that characters that are sensitive in HTML and XML markup must be escaped. This flag is set to "true" by default.

Upvotes: 3

Related Questions