Question

I'm trying break line in <h:outputText /> value.

I simply put a <br> in my value as HTML theory. But it doesn't work and a page error show up.

When I removed the <br/>. It works again properly.

My code is:

<h:outputText value="[#{order.product.code}] #{order.product.name} <br/> #{order.qty}"/>

I tried another way.

<h:outputText value="[#{order.product.code}] #{order.product.name} &#10 #{order.qty}"/>

No change at all.

Was it helpful?

Solution

Use &lt; for < & &gt; for >, then make your html tag.


Like:

&lt;br /&gt; - For <br />

Then you have to tell the renderer not to escape html tag, place escape= "false" attribute inside <h:outputText />.


According to your requirement try this,

Sample code:

<h:outputText value="value-one &lt;br /&gt; value-two &lt;br /&gt; value-three" escape="false" />

Output:

value-one 
value-two 
value-three

OTHER TIPS

Why exactly do you need <h:outputText>? You don't seem to taking benefit of any of its additional features on top of plain EL in template text.

Just get rid of it and write it like so:

[#{order.product.code}] #{order.product.name} <br/> #{order.qty}

Note that this is not possible in legacy JSP, but given that you're using PrimeFaces, which doesn't have a JSP compatible tag library (JSP is deprecated >4 years ago), then you should surely be using Facelets.

You can use multiple h:outputTex tags with < br /> tags inbetween. Try the following:

<h:outputText value="[#{order.product.code}]"/>
<br/>
<h:outputText value="#{order.product.name}"/>
<br/> 
<h:outputText value="#{order.qty}"/>

UPDATE:

Or use escape="false":

<h:outputText value="[#{order.product.code}]&lt;br /&gt;#{order.product.name}&lt;br /&gt;#{order.qty}" escape="false" />

Thank you so much everyone..! Especially @Wanna coffee and @hurleytom. Your codes really work.

<h:outputText value="[#{order.product.code}]&lt;br /&gt;#{order.product.name}&lt;br /&gt;#{order.qty}" escape="false" />

Add attribute escape="false" in h:outputText. If your value contains <br /> then you will have break line in text.

If you have a possibility to do it in Java code, <br /> should work there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top