DisplaytagColumnDecorator returns wrong row object

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

DisplaytagColumnDecorator returns wrong row object

RogerV
Hi

I'm using Struts 2.2.1 with DisplayTag 1.2. I've got a simple jsp page that contains -

    <display:table name="${functions}" uid="row" pagesize="20" requestURI="">
    <display:setProperty name="paging.banner.placement" value="bottom" />
    <display:column property="description"/>
    <display:column title=""   decorator="com.myApp.genesis.admin.tableDecorators.EditOrDeleteDecorator"/>
    </display:table>

and my decorator is as follows;

    public class EditOrDeleteDecorator implements DisplaytagColumnDecorator {

        @Override
        public Object decorate(Object arg0, PageContext context, MediaTypeEnum arg2)
                        throws DecoratorException {
               
                IdsFunction function = (IdsFunction) context.getAttribute("row");
               
                return "<a href=\"edit-function?id=" + function.getId()
                + "\">Edit | "
                + "<a href=\"delete-function?id=" + function.getId()
                + "\">Delete | "
                + "<a href=\"list-service-definitions?id=" + function.getId()
                + "\">Definitions";

        }

    }

Debugging the decorator shows that context.getAttribute("row") does indeed return an IdsFunction object, but on each iteration it's always the same IdsFunction object and it's the last IdsFunction instance in the list. I was expecting to be handed each row object in turn.

The rendered JSP displays the row objects correctly, with each member of the list displayed but obviously the URL's all point to the last member in the list.

What am I missing?

Regards
Reply | Threaded
Open this post in threaded view
|

Re: DisplaytagColumnDecorator returns wrong row object

RogerV
Sorry,

The interface I was using to post through Nabble removed a chunk of my message - I'll try again

I'm using Struts 2.2.1 with DisplayTag 1.2. I've got a simple jsp page that contains -

    <display:table name="${functions}" uid="row" pagesize="20" requestURI="">
    <display:setProperty name="paging.banner.placement" value="bottom" />
    <display:column property="description"/>
    <display:column title=""   decorator="com.myApp.genesis.admin.tableDecorators.EditOrDeleteDecorator"/>
    </display:table>

and my decorator is as follows;

    public class EditOrDeleteDecorator implements DisplaytagColumnDecorator {

        @Override
        public Object decorate(Object arg0, PageContext context, MediaTypeEnum arg2)
                        throws DecoratorException {
               
                IdsFunction function = (IdsFunction) context.getAttribute("row");
               
                return "<a href=\"edit-function?id=" + function.getId() "\">Edit</a> | "
                + "<a href=\"delete-function?id=" + function.getId() "\">Delete</a> | "
                + "<a href=\"list-service-definitions?id=" + function.getId() "\">Definitions</a>";

        }

    }

Debugging the decorator shows that context.getAttribute("row") does indeed return an IdsFunction object, but on each iteration it's always the same IdsFunction object and it's the last IdsFunction instance in the list. I was expecting to be handed each row object in turn.

The rendered JSP displays the row objects correctly, with each member of the list displayed but obviously the URL's all point to the last member in the list.

What am I missing?

Regards

Reply | Threaded
Open this post in threaded view
|

Re: DisplaytagColumnDecorator returns wrong row object

Paul Cooper-2
All decorators have a getCurrentRowObject() method that will return the object that makes up each row. Cast the result of the method to whatever Class it really is, and then call methods on it.

-----Original Message-----
From: RogerV [mailto:[hidden email]]
Sent: Thursday, March 31, 2011 4:14 AM
To: [hidden email]
Subject: Re: [displaytag-user] DisplaytagColumnDecorator returns wrong row object


Sorry,

The interface I was using to post through Nabble removed a chunk of my message - I'll try again

I'm using Struts 2.2.1 with DisplayTag 1.2. I've got a simple jsp page that contains -

    <display:table name="${functions}" uid="row" pagesize="20"
requestURI="">
    <display:setProperty name="paging.banner.placement" value="bottom" />
    <display:column property="description"/>
    <display:column title=""  
decorator="com.myApp.genesis.admin.tableDecorators.EditOrDeleteDecorator"/>
    </display:table>

and my decorator is as follows;

    public class EditOrDeleteDecorator implements DisplaytagColumnDecorator {

        @Override
        public Object decorate(Object arg0, PageContext context, MediaTypeEnum
arg2)
                        throws DecoratorException {
               
                IdsFunction function = (IdsFunction) context.getAttribute("row");
               
                return "&lt;a href=\"edit-function?id=" + function.getId() "\"&gt;Edit&lt;/a&gt; | "
                + "&lt;a href=\"delete-function?id=" + function.getId() "\"&gt;Delete&lt;/a&gt; | "
                + "&lt;a href=\"list-service-definitions?id=" + function.getId() "\"&gt;Definitions&lt;/a&gt;";

        }

    }

Debugging the decorator shows that context.getAttribute("row") does indeed return an IdsFunction object, but on each iteration it's always the same IdsFunction object and it's the last IdsFunction instance in the list. I was expecting to be handed each row object in turn.

The rendered JSP displays the row objects correctly, with each member of the list displayed but obviously the URL's all point to the last member in the list.

What am I missing?

Regards


--
View this message in context: http://old.nabble.com/DisplaytagColumnDecorator-returns-wrong-row-object-tp31275210p31284166.html
Sent from the DisplayTag - General mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Create and publish websites with WebMatrix
Use the most popular FREE web apps or write code yourself;
WebMatrix provides all the features you need to develop and
publish your website. http://p.sf.net/sfu/ms-webmatrix-sf
_______________________________________________
displaytag-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/displaytag-user

------------------------------------------------------------------------------
Create and publish websites with WebMatrix
Use the most popular FREE web apps or write code yourself;
WebMatrix provides all the features you need to develop and
publish your website. http://p.sf.net/sfu/ms-webmatrix-sf
_______________________________________________
displaytag-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/displaytag-user
Reply | Threaded
Open this post in threaded view
|

Re: DisplaytagColumnDecorator returns wrong row object

RogerV

Paul Cooper-2 wrote
All decorators have a getCurrentRowObject() method that will return the object that makes up each row. Cast the result of the method to whatever Class it really is, and then call methods on it.
DisplaytagColumnDecorator is only an interface. Which concrete decorator should I extend to create my column decorator?

Regards
Reply | Threaded
Open this post in threaded view
|

Re: DisplaytagColumnDecorator returns wrong row object

Paul Cooper-2
Roger,

I don't use the column decorator, I use the TableDecorator, which has that method. You put the decorator on the whole table, and create methods in the decorator to manipulate individual columns. If you reference a property that is not a method on the object referenced in the table, DisplayTag will then check the TableDecorator for that property.

Paul

-----Original Message-----
From: RogerV [mailto:[hidden email]]
Sent: Thursday, March 31, 2011 10:40 AM
To: [hidden email]
Subject: Re: [displaytag-user] DisplaytagColumnDecorator returns wrong row object




Paul Cooper-2 wrote:
>
> All decorators have a getCurrentRowObject() method that will return
> the object that makes up each row. Cast the result of the method to
> whatever Class it really is, and then call methods on it.
>

DisplaytagColumnDecorator is only an interface. Which concrete decorator should I extend to create my column decorator?

Regards

--
View this message in context: http://old.nabble.com/DisplaytagColumnDecorator-returns-wrong-row-object-tp31275210p31286984.html
Sent from the DisplayTag - General mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Create and publish websites with WebMatrix
Use the most popular FREE web apps or write code yourself;
WebMatrix provides all the features you need to develop and
publish your website. http://p.sf.net/sfu/ms-webmatrix-sf
_______________________________________________
displaytag-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/displaytag-user

------------------------------------------------------------------------------
Create and publish websites with WebMatrix
Use the most popular FREE web apps or write code yourself;
WebMatrix provides all the features you need to develop and
publish your website. http://p.sf.net/sfu/ms-webmatrix-sf
_______________________________________________
displaytag-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/displaytag-user