This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread 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


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()
 
jQuery in Action, 2nd edition
 
subject: Limit characters returned in H:Outputtext?