如何修改displaytag中某一列的空值?

How to modifiy the empty value of a column in displaytag?

如果列的值为空,DisplayTag 将打印一个空字符串。 这是在 org.displaytag.model.Column#getValue 方法中执行此操作的源代码:

if (object == null || "null".equals(object)) //$NON-NLS-1$
{
    if (!this.header.getShowNulls())
    {
        object = TagConstants.EMPTY_STRING;
    }
}

我想知道是否有办法覆盖它并显示特定值而不是空字符串。我正在寻找的是 generic/automatic 解决方案,否则我可以通过测试我的对应于该列的属性是否为 null 并在需要时返回特定字符来手动处理该问题...

您可以使用装饰器根据需要自定义任何列的值:

例子

http://demo.displaytag.org/displaytag-examples-1.2/example-decorator.jsp

标签参考:

http://www.displaytag.org/10/tagreference-displaytag-12.html

从而创建一个class:

public class MyCustomColumnDecorator implements DisplaytagColumnDecorator{

    public Object decorate(Object columnValue, PageContext pageContext, MediaTypeEnum media) {
        return value == null ? "some string" : value;
    }
}

在您希望将其用于任何列的标记中指定:

<display:table name="someList">
  <display:column sortable="true" title="ID"/>
  <display:column property="email" autolink="true"/>
  <display:column property="description" title="Comments" decorator="com.test.MyCustomColumnDecorator"/>
</display:table>