Details
-
Type:
Bug
-
Status:
Open
-
Priority:
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>
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>