wood burning stoves*
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 Android Security Essentials Live Lessons this week in the Android 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()
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Limit characters returned in H:Outputtext?
 
Similar Threads
Special Characters '&' and ':'
Datatable column header issue
h:inputText in h:dataTable, request scoped bean
retrieve a int from backbean and dinamically work with it in the .xhtml in very bizarre way
I know this should work, so what is wrong?