This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSF and the fly likes Limit characters returned in H:Outputtext? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Limit characters returned in H:Outputtext?" Watch "Limit characters returned in H:Outputtext?" New topic
Author

Limit characters returned in H:Outputtext?

Dan Acuff
Ranch Hand

Joined: Jul 13, 2009
Posts: 62
Is there anyway to limit the number of characters returned in an <h:OUTPUTTEXT/> ? The value attribute I mean...




Or will I need to call a method behind to do the work?

If I build a method.. how will this string of code at least look differently?

Will I use an actionlistener?
Rory Evans
Greenhorn

Joined: Feb 19, 2010
Posts: 18
The API for outputtext makes no mention of a parameter such as 'maxLength'.

I would have a method on a backing bean which in turn gets the string you want displayed and truncates it.

Maybe something like:



With a method on your backing bean like:



Where 10 is your desired number of characters to display in the outputtext
Dan Acuff
Ranch Hand

Joined: Jul 13, 2009
Posts: 62
Thanks Rory. That gives me a good start.
Getting it to work in a full blown seam environment is another story ...

Do I have to tie it into the interface in any way?

I am getting an error:
value="#{_item.truncateBenefitsString}": Property 'truncateBenefitsString' not found on type com.thissource.webstore.entity.Item

Or do I need to set Setters and Getters?

Thank you from,
Total Java Newb!
Rory Evans
Greenhorn

Joined: Feb 19, 2010
Posts: 18
Try renaming the truncateBeansString() method to getTruncateBeanString()
 
Don't get me started about those stupid light bulbs.
 
subject: Limit characters returned in H:Outputtext?