jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • DisplayTag
  • DISPL-550

uid always returns the same object in column decorators

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Critical Critical
  • Resolution: Unresolved
  • Affects Version/s: 1.1.1
  • Fix Version/s: 1.3
  • Component/s: Decorators
  • Labels:
    None

Description

Using the uid property of the table tag ("<display:table uid="row">") does not set the current row object in the page scope. It just put the last table row in pageScope.

Here is an extract of the org.displaytag.tags.TableTag.doIteration() on line 784 :

if (this.tableIterator.hasNext())
{
  Object iteratedObject = this.tableIterator.next();
  [...]
  this.pageContext.setAttribute(getUid(), iteratedObject);


So when the JSP is rendered, the iterator is called. For each table line, the iteratedObject overwrites the previous row. Then, after all row have been read, the column decorators are called. So If a decorator need the current row object, accessed using the provided pageContext, it will only find the last row object.

The Javadoc for "uid" is : "The object representing the current row is also added to the pageContext under this name and the current row number is added using the key uid_rowNum." So in a column decorator, using pageContext, we can presume to have access to the current row object. This is not the case : the last table row is the only object in pageScope.

Example of a column decorator which does not have access to its current row object :

public class WorkflowStepColumnDecorator implements DisplaytagColumnDecorator {
  public Object decorate(Object columnValue, PageContext pageContext, MediaTypeEnum media) throws DecoratorException {
    Object row = pageContext.getAttribute("row");
    // row is not the current row, it is the last table's row
  }
}

JSP code :
<display:table uid="row" name="users">
  <display:column decorator="example.MyColumnDecorator "/>
</display:table>


Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Tom Stroobants added a comment - 07/Jul/10 4:57 AM
This is not fixed in version 1.2 as mentioned in History.
Show
Tom Stroobants added a comment - 07/Jul/10 4:57 AM This is not fixed in version 1.2 as mentioned in History.
Hide
Permalink
Pietro Martinelli added a comment - 10/Jan/12 10:03 AM
What about resolving this issue by changing DisplaytagColumnDecorator.decorate method's signature?
Something like

public Object decorate(Object columnValue, Object currentRowObject, PageContext pageContext, MediaTypeEnum media) ?

This manner column decorators can access current row object and displaytag internal data structure's lifecycle can remain unchanged.

But column decorators are used for totals cell formatting, too: it may look ugly pass currentRowObject == null when decorating header/footer cells. An alternative solution may consist in adding two methods to DisplaytagColumnDecorator interface:
public Object decorate(Object columnValue, Object currentRowObject, PageContext pageContext, MediaTypeEnum media)
public Object decorateTotals/Headers(Object columnValue, PageContext pageContext, MediaTypeEnum media)

A further alternative would be to pass to decorate method something like DecorableCell interface:

public interface DecorableCell {
  Object getCellValue();
  Integer getIterationIndex();
  Object getCurrentRowObject();
  boolean isBodyCell();
}

I've developed a solution hypotesis following the first proposal and it seems work fine.
Show
Pietro Martinelli added a comment - 10/Jan/12 10:03 AM What about resolving this issue by changing DisplaytagColumnDecorator.decorate method's signature? Something like public Object decorate(Object columnValue, Object currentRowObject, PageContext pageContext, MediaTypeEnum media) ? This manner column decorators can access current row object and displaytag internal data structure's lifecycle can remain unchanged. But column decorators are used for totals cell formatting, too: it may look ugly pass currentRowObject == null when decorating header/footer cells. An alternative solution may consist in adding two methods to DisplaytagColumnDecorator interface: public Object decorate(Object columnValue, Object currentRowObject, PageContext pageContext, MediaTypeEnum media) public Object decorateTotals/Headers(Object columnValue, PageContext pageContext, MediaTypeEnum media) A further alternative would be to pass to decorate method something like DecorableCell interface: public interface DecorableCell {   Object getCellValue();   Integer getIterationIndex();   Object getCurrentRowObject();   boolean isBodyCell(); } I've developed a solution hypotesis following the first proposal and it seems work fine.

People

  • Reporter:
    Thomas Queste
Vote (2)
Watch (1)

Dates

  • Created:
    30/Jun/08 11:19 AM
    Updated:
    10/Jan/12 10:04 AM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.