1

Mojara 2.1.21, Primefaces 3.5, Omnifaces 1.5 Is it possible in JSF to use a component that preserve whitespaces and new lines ? I have something like that:

<c:forEach items="{bean.items}" var="item">
   <h:outputText value="#{item.text}" />
   <p:inputText value="#{item.getText[item.id]}" />
</c:forEach >
Tony
  • 2,266
  • 4
  • 33
  • 54

1 Answers1

5

Instead of staring at JSF source code, you should first investigate how the generated HTML output should look like in order to achieve the concrete UI requirement. In plain HTML terms, you can achieve that by either putting the text content in a HTML <pre> element, or to apply CSS white-space:pre style on the parent element.

None of them have a JSF component equivalent. But that's also not necessary. You can just write HTML and CSS the usual way in JSF.

<pre><h:outputText value="#{item.text}" /></pre>

or

<h:outputText value="#{item.text}" style="white-space: pre;" />

(note: above example is intented as kickoff, normal practice is to use a normal CSS class)

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you for your answer! My idea was to use

    . But your answer is much simpler (and better).

    – Tony Sep 16 '13 at 14:40
  • You're welcome. Note that `

    ` doesn't preserve formatting. It has semantically also a different meaning (a paragraph).

    – BalusC Sep 16 '13 at 14:45