You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Michael Taylor <mi...@google.com> on 2010/09/24 18:11:02 UTC

Loop values & AJAX refreshing components

 I’m having some issues with using an ajax refreshing component inside a
loop, and I’m hoping someone can help.
I have a component that contains an zone that I’m updating using a ajax
request and an action link.  In the onAction handler for the event link I do
a data lookup based on an ID that I pass into the component as a paramter.
Now if I have a page that contains this component and has a property that
contains the data Id everything works fine.
However if instead of a single data id I make the containing page have a
property that is a List of data ids, loop over these ids in the template,
for each one adding the component and passing the “current” id as a
parameter I run into trouble.
During the component’s “SetupRender” the parameter value is what I expect.
 However in the subsequent calls to the action link handler I discover that
the parameter has reverted to “0”.
It looks like at the point of the action link invocation, tapestry is trying
to recompute the parameter value based on the containing page, but since the
containing page doesn’t re-render, there is no loop and as a result the
“current” loop iteration property is “0”.
Can anyone suggest a way to get around this limitation?


Regards,

Mike T

Re: Loop values & AJAX refreshing components

Posted by Christian Gruber <ch...@gmail.com>.
On Sep 24, 2010, at 2:58 PM, Thiago H. de Paula Figueiredo wrote:

>> 
> 
>> 1. In my SetupRender method I assign the parameter value to a property foo of the component.
> 
> I can't see why you need this.

Because initially the value comes in from a parameter, but on refresh the value comes in from the event handler, and you can't re-assign to the @parameter variable, or tapestry complains.  So "foo" is the intermediary that both the component param and the event parm get passed into, so that the rest of hte component can cleanly access from one location.

Christian.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Loop values & AJAX refreshing components

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Fri, 24 Sep 2010 15:22:50 -0300, Michael Taylor <mi...@google.com>  
wrote:

> Thanks Thiago!

You're welcome!

> So for the record I had to

> 1. In my SetupRender method I assign the parameter value to a property  
> foo of the component.

I can't see why you need this.

> 2. Made my onActionFromRefreshZoneLink method take a context parameter  
> which
> I also assign to the same component property.
> 3. Add a t:context attribute to my action link similar to
>
> <a t:type="actionlink" t:id="refreshZoneLink" href="#"
> *t:context="${foo}"*t:zone="theZone">Refresh</a>

Never ever use an expansion (${}) when passing parameters, as it forces a  
conversion to String before passing the value to the component parameter.

> 4. Modify my data fetching to use the value from the component property  
> foo instead of using the parameter value directly.
> In this way I can get the id from the parameter on the initial render and
> from the action link context on the subsequent ajax refreshes.
> Not sure if this is the cleanest solution, but it seems to work.

I haven't seen your code, so I can't say if there's a better solution.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Loop values & AJAX refreshing components

Posted by Michael Taylor <mi...@google.com>.
Thanks Thiago!
So for the record I had to

1. In my SetupRender method I assign the parameter value to a property foo
of the component.
2. Made my onActionFromRefreshZoneLink method take a context parameter which
I also assign to the same component property.
3. Add a t:context attribute to my action link similar to

<a t:type="actionlink" t:id="refreshZoneLink" href="#"
*t:context="${foo}"*t:zone="theZone">Refresh</a>

4. Modify my data fetching to use the value from the component property foo
instead of using the parameter value directly.

In this way I can get the id from the parameter on the initial render and
from the action link context on the subsequent ajax refreshes.

Not sure if this is the cleanest solution, but it seems to work.

Thanks again.

Mike T


On Fri, Sep 24, 2010 at 1:01 PM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Fri, 24 Sep 2010 13:11:02 -0300, Michael Taylor <mi...@google.com>
> wrote:
>
>  It looks like at the point of the action link invocation, tapestry is
>> trying to recompute the parameter value based on the containing page, but
>> since the containing page doesn’t re-render, there is no loop and as a
>> result the
>> “current” loop iteration property is “0”.
>>
>
> You can't rely on the loop iteration property when the loop is not being
> rendered. You need to pass the id as the context to your ActionLink.
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> and instructor
> Owner, Ars Machina Tecnologia da Informação Ltda.
> http://www.arsmachina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Loop values & AJAX refreshing components

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Fri, 24 Sep 2010 13:11:02 -0300, Michael Taylor <mi...@google.com>  
wrote:

> It looks like at the point of the action link invocation, tapestry is  
> trying to recompute the parameter value based on the containing page,  
> but since the containing page doesn’t re-render, there is no loop and as  
> a result the
> “current” loop iteration property is “0”.

You can't rely on the loop iteration property when the loop is not being  
rendered. You need to pass the id as the context to your ActionLink.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org