Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add break line in <h:outputText /> value?

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.

like image 208
Zin Win Htet Avatar asked Feb 28 '14 07:02

Zin Win Htet


4 Answers

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
like image 62
Wanna Coffee Avatar answered Nov 16 '22 03:11

Wanna Coffee


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.

like image 20
BalusC Avatar answered Nov 16 '22 03:11

BalusC


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" />
like image 2
hurleytom Avatar answered Nov 16 '22 01:11

hurleytom


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" />
like image 2
Zin Win Htet Avatar answered Nov 16 '22 02:11

Zin Win Htet