Represents a column in a table.
| Method from org.displaytag.model.Column Detail: |
public String createChoppedAndLinkedValue() throws DecoratorException, ObjectLookupException {
String fullValue = ObjectUtils.toString(getValue(true));
String choppedValue;
// trim the string if a maxLength or maxWords is defined
if (this.header.getMaxLength() > 0)
{
choppedValue = HtmlTagUtil.abbreviateHtmlString(fullValue, this.header.getMaxLength(), false);
}
else if (this.header.getMaxWords() > 0)
{
choppedValue = HtmlTagUtil.abbreviateHtmlString(fullValue, this.header.getMaxWords(), true);
}
else
{
choppedValue = fullValue;
}
// chopped content? add the full content to the column "title" attribute
// note, simply checking that length is less than before can't be enough due to the "..." added if the string is
// cropped
if (!ObjectUtils.equals(fullValue, choppedValue))
{
// clone the attribute map, don't want to add title to all the columns
this.htmlAttributes = (HtmlAttributeMap) this.htmlAttributes.clone();
// add title
this.htmlAttributes.put(TagConstants.ATTRIBUTE_TITLE, HtmlTagUtil.stripHTMLTags(fullValue));
}
if (this.header.getHref() != null)
{
// generates the href for the link
Href colHref = getColumnHref(fullValue);
Anchor anchor = new Anchor(colHref, choppedValue);
choppedValue = anchor.toString();
}
return choppedValue;
}
Calculates the cell content, cropping or linking the value as needed. |
public String getChoppedAndLinkedValue() {
return this.stringValue;
}
get the final value to be displayed in the table. This method can only be called after initialize(), where the
content is evaluated |
public String getCloseTag() {
this.stringValue = null;
return this.header.getCloseTag();
}
Generates the cell close tag (</td>). |
public HeaderCell getHeaderCell() {
return this.header;
}
Get the header cell for this column. |
public String getOpenTag() {
HtmlAttributeMap rowAttributes = cell.getPerRowAttributes();
HtmlAttributeMap atts = htmlAttributes;
if (rowAttributes != null)
{
atts = (HtmlAttributeMap) atts.clone();
atts.putAll(rowAttributes);
}
return HtmlTagUtil.createOpenTagString(TagConstants.TAGNAME_COLUMN, atts);
}
Generates the cell open tag. |
public Object getValue(boolean decorated) throws DecoratorException, ObjectLookupException {
Object object = null;
// a static value has been set?
if (this.cell.getStaticValue() != null)
{
object = this.cell.getStaticValue();
}
else if (this.header.getBeanPropertyName() != null)
{
// if a decorator has been set, and if decorator has a getter for the requested property only, check
// decorator
if (decorated
&& this.row.getParentTable().getTableDecorator() != null
&& this.row.getParentTable().getTableDecorator().hasGetterFor(this.header.getBeanPropertyName()))
{
object = LookupUtil.getBeanProperty(this.row.getParentTable().getTableDecorator(), this.header
.getBeanPropertyName());
}
else
{
// else check underlining object
object = LookupUtil.getBeanProperty(this.row.getObject(), this.header.getBeanPropertyName());
}
}
DisplaytagColumnDecorator[] decorators = this.header.getColumnDecorators();
if (decorated)
{
for (int j = 0; j < decorators.length; j++)
{
object = decorators[j].decorate(object, row.getParentTable().getPageContext(), row
.getParentTable()
.getMedia());
}
}
if (object == null || "null".equals(object)) //$NON-NLS-1$
{
if (!this.header.getShowNulls())
{
object = TagConstants.EMPTY_STRING;
}
}
return object;
}
Gets the value, after calling the table / column decorator is requested. |
public void initialize() throws DecoratorException, ObjectLookupException {
if (this.stringValue == null)
{
this.stringValue = createChoppedAndLinkedValue();
}
}
Initialize the cell value. |
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) //
.append("cell", this.cell) //$NON-NLS-1$
.append("header", this.header) //$NON-NLS-1$
.append("htmlAttributes", this.htmlAttributes) //$NON-NLS-1$
.append("stringValue", this.stringValue) //$NON-NLS-1$
.toString();
}
|