This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSF and the fly likes Wrapping long text using h:outputText Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Wrapping long text using h:outputText" Watch "Wrapping long text using h:outputText" New topic

Wrapping long text using h:outputText

Dhananjay Inamdar
Ranch Hand

Joined: Jan 27, 2003
Posts: 130
I am using JSF as a front-end technology for one of my project. My application works on Tomcat web server. In my application, on one of page, I have to extract a data from database and have to display on the page.

I am extracting a data from database and populates it in the java bean. I am using h: outputText While displaying data on the jsf page. My code is as follows

<hutputText value="#{leg.transport}" styleClass="lightGray"/>

It works fine and displays data on the screen.

Problem is when data is too long in the database then all data gets displayed in one line. Horizontal scrollbar gets added to the page, as some of the data is of 1500 character length.

I will like to know the way of wrapping a text in the JSF. So that while displaying data on the page, I will wrap the text and page will display within the limit of browser.

Just like you, struggeling to get the right solutions!<br /> <br />Sun Certified Java Programmer 1.5<br /> <br />Target - SCWCD
Henrique Sousa
Ranch Hand

Joined: Apr 29, 2004
Posts: 92
Which element is the outputText in? And what are the style rules for "lightGray" CSS class? In most HTML elements, text is wrapped correctly. Exceptions for absolutely positioned elements and those with "white-space: nowrap" CSS attribute.
As a workaround, try to define a width for the element to see if the text gets wrapped. If M$IE accepted "max-width" CSS attribute, I would recommend it. Regards

Henrique Sousa<br />SCJP 1.4<br /> <br />All men die, not all men really live - Braveheart, 1995
Dhananjay Inamdar
Ranch Hand

Joined: Jan 27, 2003
Posts: 130
I have something like:

<h utputText value="Services" styleClass="lightBG" />
<h anelGrid columns="4" rowClasses="darkGray,lightGray" width="650px" cellpadding="0" cellspacing="2" border="0" >

and within this I have

<h utputText value="#{leg.transport}" styleClass="lightGray"/>

Can you please guide me in wrapping the text above. I want to avaoid the horizontal scroll bar that comes when the data length is too long.

Henrique Sousa
Ranch Hand

Joined: Apr 29, 2004
Posts: 92
Well, the generated HTML should be something like this

This is expected to work as you intend, unless some of the style rules says white-space: nowrap. If you are using Firefox it would be easy to change the td element to include white-space: normal using DOM Inspector and see what happens. Otherwise, you should do it manually. The intended result is something like this:

If the text does not contains white spaces you have a big problem because then it will not be wrapped anyway.
wood burning stoves
subject: Wrapping long text using h:outputText
Similar Threads
populating jsp page dynamically
Issue in submitting the Form with Arraylist in Struts 1.1
Displaying h:columns in different rows
Can we execute two sql statements with one Connection object?
Bean gets instantiated again in one request