I need to render a line break using outputText
so that I can utilize the rendered
attributed. I tried
<h:outputText value="<br/>" escape="false" />
but it generated exception
The value of attribute "value" associated with an element type "null" must not contain the '<' character.
In Windows, a new line is denoted using “\r\n”, sometimes called a Carriage Return and Line Feed, or CRLF. Adding a new line in Java is as simple as including “\n” , “\r”, or “\r\n” at the end of our string.
Press ALT+ENTER to insert the line break.
Add attribute escape="false" in h:outputText . If your value contains <br /> then you will have break line in text.
The <br> HTML element produces a line break in text (carriage-return).
That's indeed not valid since Facelets because it's syntactically invalid in XML. You'd need to manually escape the XML special characters like <
, >
and so on.
<h:outputText value="<br/>" escape="false" />
You can however just emit the <br/>
in template text without the need for a <h:outputText>
.
<br/>
To render it conditionally, wrap it in for example a <ui:fragment>
.
<ui:fragment rendered="#{bean.rendered}"><br /></ui:fragment>
A <h:panelGroup>
is also valid as it doesn't emit anything to the HTML anyway.
<h:panelGroup rendered="#{bean.rendered}"><br /></h:panelGroup>
JSF PAGE
<h:outputText value="#{car.crg}" escape="false" style="white-space: pre-wrap;word-wrap: break-word; " />
escape should be false
and write the bean Getter
method as follows
public String getCrg() { return crg.replace("<br/>", "<br />"); //return crg; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With