I used <t:buffer and a facelet function.
JSF:
<t:buffer into="#{tempStr}">
JSF tags go here
</t:buffer>
<t:outputText value="#{fn:truncateString(tempStr, 53, '...')}" />
Java:
public static String truncateString(String value, int maxLength,
String terminator)
{
if (value.length() < maxLength) return value;
if (terminator == null) return value.substring(0, maxLength);
return value.substring(0, Math.min(0, maxLength -
terminator.length())) + terminator;
}
On 4/6/06, Adam Winer <[EMAIL PROTECTED]> wrote:
> FWIW, the ADF af:outputText component has a "truncateAt"
> attribute.
>
> -- Adam
>
>
> On 4/6/06, Gary VanMatre <[EMAIL PROTECTED]> wrote:
> >
> > >From: "Lindholm, Greg" <[EMAIL PROTECTED]>
> >
> > >
> > > Is there a way to truncate outputText and specify the size
> > > you want from a jsp page?
> > >
> > > I have an object with a long description property.
> > > When it's listed in a dataTable I want to truncate the
> > > description column to X characters.
> > > Where X can be specified for that column.
> > >
> > > I know I can add a getTruncatedDescription() method to the
> > > object but I think a more general facility would be
> > > really useful.
> > >
> > > Does anybody have a way or doing this with current tags?
> > >
> > > Is this something that could be done with a converter?
> > >
> > > Is this something that could be added to ?
> > >
> >
> > Sure. How about something like this:
> >
> > JSP:
> > <h:dataTable value="#{mybean.data}" var="e">
> > <h:column>
> > <h:outputText binding="#{mybean.output}" value="#{e.chapter}"/>
> > </h:column>
> > </h:dataTable>
> >
> > Custom Converter:
> > public class TrunkConverter implements Converter {
> > private int maximumSize = -1;
> >
> > public int getMaximumSize() {
> > return maximumSize;
> > }
> >
> > public void setMaximumSize(int maximumSize) {
> > this.maximumSize = maximumSize;
> > }
> >
> > public Object getAsObject(FacesContext context, UIComponent component,
> > String value) throws ConverterException {
> > return value;
> > }
> > public String getAsString(FacesContext context, UIComponent component,
> > Object value) throws ConverterException {
> > StringBuffer buff = new StringBuffer();
> > buff.append(value);
> > buff.setLength(maximumSize);
> >
> > return buff.toString();
> > }
> >
> > }
> >
> > Backing Bean:
> > private HtmlOutputText output = null;
> > public HtmlOutputText getOutput() {
> > if (output == null) {
> > output = new HtmlOutputText();
> > FacesContext context = FacesContext.getCurrentInstance();
> > context.getApplication().addConverter("com.acme.TrunkConverter",
> > "com.acme.TrunkConverter");
> > TrunkConverter converter = (TrunkConverter)
> > context.getApplication().createConverter("com.acme.TrunkConverter");
> > converter.setMaximumSize(5);
> > output.setConverter(converter); &n bsp;
> > }
> >
> > return output;
> > }
> > public void setOutput(HtmlOutputText output) {
> > this.output = output;
> > }
> >
> >
> >
> > >
> >
> >
> > Gary
>