>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?
>
>
> 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
>
JSP:
<h:dataTable value="#{mybean.data}" var="e">
<h:column>
<h:outputText binding="#{mybean.output}" value="#{e.chapter}"/>
</h:column>
</h:dataTable>
<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;
}
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();
}
}
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;
}
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;
}

