You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Charles Mason <ch...@gmail.com> on 2007/09/17 14:24:06 UTC

T5: A Hopefully Simple Question About Action Link Scope

Hi All

I am currently experiencing a problem which seems to contradict the
model of how action link works.

I have a page called start.html. It has a for loop which for every
iteration contains a custom component, called MatchInfo. This renders
a box containing the info about the match. MatchInfo has an action
link tag and event method, which does something with the match. The
method called by the action link uses the persistent field which
stores the actual Match object which the component gets data from.

However when ever I use the page and click the action link, its as
though the action link is clicked on the last MatchInfo component,
even when I click the action link on a different MatchInfo component.

I thought the action link would call the method of the component
object that generated it not just the last object. I am not sure if
this is a bug or a "Feature"?

Can anyone shed some light on this for me.

Charlie M

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


Re: T5: A Hopefully Simple Question About Action Link Scope

Posted by Charles Mason <ch...@gmail.com>.
On 9/17/07, Davor Hrg <hr...@gmail.com> wrote:
> The problem is that you must give action link something
> to identify your object.
>
> in the page you mentioned you have only one instance of
> the MatchInfo component that get's rendered multiple times with different
> data.
> So when your action is called, you have the last element passed as
> parameter.

That's what really confused me. I wrongly thought you would get a new
MatchInfo Object for every iteration of the loop. Thanks for clearing
that up.


> if in you AppModule you make following TypeCoercers :
> String->DateeeMatch
> and
> DateeeMatch -> String

I have been looking at Type Coercion, and I am still a little
confused. As I understand it I need to provide a way for Tapestry to
convert my DateeeMatch object to a string.

The DateeeMatch is too complex to serialise directly in to the page.
Is there some way, I can store it in the session, then use some type
of ID to retrieve the correct object from the session. I could then
just put the ID in the actually URL.

Is there some standard way of providing this type of Coercion in
tapestry or do I need to implement all storing to and retrieving from
the session functionality my self.

According to the docs there's a standard Object -> String coercion in
built in, I am currently trying to find the source of that to see if
that will give me any pointers.

Is this the best approach to Coercion of more complex objects (not
single data objects like Strings)? Thanks again for the help.

Charlie M

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


Re: T5: A Hopefully Simple Question About Action Link Scope

Posted by Davor Hrg <hr...@gmail.com>.
The problem is that you must give action link something
to identify your object.

in the page you mentioned you have only one instance of
the MatchInfo component that get's rendered multiple times with different
data.
So when your action is called, you have the last element passed as
parameter.

you shoud link it like this:

<t:actionlink t:id="changedMind" context="match.id">Changed Your
Mind</t:actionlink>

       public void onActionFromChangedMind(Long id)
       {
              //load match from database by the id
              System.out.println(match.getName());
       }

-----------------------------------------------------------------------------------------------------
if in you AppModule you make following TypeCoercers :
String->DateeeMatch
and
DateeeMatch -> String


above code can look like this:


<t:actionlink t:id="changedMind" context="match">Changed Your
Mind</t:actionlink>

       public void onActionFromChangedMind(DateeeMatch match)
       {
              //load match from database by the id
              System.out.println(match.getName());
       }



Davor Hrg




On 9/17/07, Charles Mason <ch...@gmail.com> wrote:
>
> On 9/17/07, Francois Armand <fa...@linagora.com> wrote:
> > Well, I'm not sure that I understand what you do correctly, may you
> > provide the actual code ?
> > As far as I can tell, you persists a field that is used as value for the
> > loop, and so it's always the last MacthInfo that is persists.
> >
> > You may want to have a look at
> > http://tapestry.apache.org/tapestry5/tapestry-core/guide/pagenav.html
> > and look how Tapestry deals with context and onActivate/onPassivate
> methods.
>
> Thanks for your reply however, I don't think was very clear about what
> I'm trying to do.
>
> I was trying to avoid posting code from lots of different files but. I
> think I can find the relevant snippets, which should make things
> clearer.
>
> So here goes:
>
> From Start.html:
>
>        <t:loop source="Matches" value="CurrentMatch">
>              <t:MatchInfo match="CurrentMatch" />
>        </t:loop>
>
> From Start.java:
>
>     @Persist
>     private List<DateeeMatch> matches;
>
>     @Persist
>     private DateeeMatch currentMatch;
>
> matches is filled from a long DB query.
>
> The action link in MatchInfo.html:
>
>     <td class="matchLink">
>         <t:actionlink t:id="changedMind">Changed Your Mind</t:actionlink>
>     </td>
>
> From MatchInfo.java
>
>         @Parameter(required=true)
>         private DateeeMatch match;
>
>
>         public void onActionFromChangedMind()
>         {
>                 System.out.println(match.getName());
>         }
>
>
> My problem is when you click the action link on any of the MatchInfo
> components on the start page. The console shows the name of the last
> match not the one clicked on. The MatchInfo component also correctly
> displays lots of info from the match parameter, so that is defiantly
> OK.
>
> Can anyone shed some light on this for me?
>
> Charlie M
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5: A Hopefully Simple Question About Action Link Scope

Posted by Charles Mason <ch...@gmail.com>.
On 9/17/07, Francois Armand <fa...@linagora.com> wrote:
> Well, I'm not sure that I understand what you do correctly, may you
> provide the actual code ?
> As far as I can tell, you persists a field that is used as value for the
> loop, and so it's always the last MacthInfo that is persists.
>
> You may want to have a look at
> http://tapestry.apache.org/tapestry5/tapestry-core/guide/pagenav.html
> and look how Tapestry deals with context and onActivate/onPassivate methods.

Thanks for your reply however, I don't think was very clear about what
I'm trying to do.

I was trying to avoid posting code from lots of different files but. I
think I can find the relevant snippets, which should make things
clearer.

So here goes:

>From Start.html:

       <t:loop source="Matches" value="CurrentMatch">								
             <t:MatchInfo match="CurrentMatch" />
       </t:loop>

>From Start.java:

    @Persist
    private List<DateeeMatch> matches;

    @Persist
    private DateeeMatch currentMatch;

matches is filled from a long DB query.

The action link in MatchInfo.html:

    <td class="matchLink">
        <t:actionlink t:id="changedMind">Changed Your Mind</t:actionlink>
    </td>

>From MatchInfo.java
	
	@Parameter(required=true)
	private DateeeMatch match;

	
	public void onActionFromChangedMind()
	{
		System.out.println(match.getName());
	}


My problem is when you click the action link on any of the MatchInfo
components on the start page. The console shows the name of the last
match not the one clicked on. The MatchInfo component also correctly
displays lots of info from the match parameter, so that is defiantly
OK.

Can anyone shed some light on this for me?

Charlie M

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


Re: T5: A Hopefully Simple Question About Action Link Scope

Posted by Francois Armand <fa...@linagora.com>.
Charles Mason wrote:
> Hi All
> [..]
>   

Hi,
> [..] The
> method called by the action link uses the persistent field which
> stores the actual Match object which the component gets data from.
>
> However when ever I use the page and click the action link, its as
> though the action link is clicked on the last MatchInfo component,
> even when I click the action link on a different MatchInfo component.
>   
Well, I'm not sure that I understand what you do correctly, may you 
provide the actual code ?
As far as I can tell, you persists a field that is used as value for the 
loop, and so it's always the last MacthInfo that is persists.

You may want to have a look at 
http://tapestry.apache.org/tapestry5/tapestry-core/guide/pagenav.html 
and look how Tapestry deals with context and onActivate/onPassivate methods.

-- 
Francois Armand
Etudes & Développements J2EE
Groupe Linagora - http://www.linagora.com
Tél.: +33 (0)1 58 18 68 28
-----------
InterLDAP - http://interldap.org 
FederID - http://www.federid.org/
Open Source identities management and federation


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