0

I am using primefaces datatable to show some data and I would like to limit the text shown to the user. I have a description that contains hundreds of lines, but I don't want to show more than 50 characters in the datatable before the user taps that row. How can I do this? I searched the JSF Api, but no luck.

LuckyLuke
  • 47,771
  • 85
  • 270
  • 434

2 Answers2

3

Inspired by this answer you could use the JSTL function substring for this purpose:

<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
...
<h:outputText value="#{fn:substring(yourBean.text, 0, 49)}" />
Community
  • 1
  • 1
Matt Handy
  • 29,855
  • 2
  • 89
  • 112
  • Ah, thank you. I actually looked at the function in the book and probably didn't read it properly =) – LuckyLuke Oct 27 '11 at 19:01
  • You should prepare your self something call "description". Some ridiculous situation i met when substring, casuse the misunderstood (English not my mothertougle so i don't know any example in English about this situation :| ). – BachT Oct 28 '11 at 19:03
  • Note that using JSTL fn:substring(), it is not necessary to check the string length. If too small, this does not give a StringIndexOutOfBoundsException - unlike String.substring(). – Kevin Swann May 15 '18 at 09:09
1

There are few suggestions on shrinking data:

1- InputText's maxlength attribute, javadoc says:

Maximum number of characters that may be entered in this field.

But I am not sure if it will shrink data which goes from server-side rather than client-side.

2- Another suggestion is getting from shortened value from server-side backing bean.

And few on expanding data:

  1. If it is JSF 2.0, use out of box ajax functions, it has it , not sure about PrimeFaces.
  2. If it is JSF1.2 (or higher) I would suggest use of toggle actions.

Hope this provides any help.

d1e
  • 6,372
  • 2
  • 28
  • 41