You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jose Gonzalez Gomez <jg...@gmail.com> on 2005/01/03 13:13:27 UTC

Accessing component that fired event in listener

Another question... if you want to create a listener in a page or
component, you just have to create a method with the following
signature:

public void myListener( IRequestCycle cycle)

but in IActionListener you have the following method:

void actionTriggered(IComponent component, IRequestCycle cycle)

where component is the component that fired the event. Is there any
way to access that component in the myListener method? Should I write
a listener class to be able to access the component?

Thanks in advance, best regards
Jose

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


Re: Accessing component that fired event in listener

Posted by Mikaël Cluseau <nw...@nwrk.dyndns.org>.
Le mardi 04 janvier 2005 à 10:23 +0100, Jose Gonzalez Gomez a écrit :
> Let's say you have three (really a variable number) components nested
> in a page, all of them are forms that edit some information and have
> their own listeners included in the component java class that do
> something. They also have a listener parameter (after the prior
> discussion, you finally convinced me :o) ) so they give the enclosing
> page an opportunity to do something after the component has done its
> stuff. The problem is that I would like to do something in the page
> depending on the component that fired the event and the data used to
> fire the event in the component. If I had access to the component that
> fired the event in the page's listener I would be able to do it, but
> that information seems to be discarded when calling the page's
> listener using the synthetic listener. Your solution would work in
> case you would have only a component, or maybe using some nasty hack,
> informing those values inside the component's listener, so they're
> available to the page's listener when is called. I think I would
> prefer to create my own IActionListener to receive the component as a
> parameter insted of doing that. The question is, why is that
> information discarded? Is there any cleaner way to do this? Am I
> missing anything?

I think my code works. The only problem was, has answered on the list,
that the listener parameters should have direction="auto". Anyway, since
the code nether lies, I did a small project to demonstrate how I see
things (attachement).


Re: Accessing component that fired event in listener

Posted by Jose Gonzalez Gomez <jg...@gmail.com>.
I think we aren't understanding ourselves again. I told you I didn't
fully understand the code, and after rereading it, I have the feeling
that you didn't understand what I was trying to achieve. Anyway, this
is a different problem, although related. I'll try to explain better.

Let's say you have three (really a variable number) components nested
in a page, all of them are forms that edit some information and have
their own listeners included in the component java class that do
something. They also have a listener parameter (after the prior
discussion, you finally convinced me :o) ) so they give the enclosing
page an opportunity to do something after the component has done its
stuff. The problem is that I would like to do something in the page
depending on the component that fired the event and the data used to
fire the event in the component. If I had access to the component that
fired the event in the page's listener I would be able to do it, but
that information seems to be discarded when calling the page's
listener using the synthetic listener. Your solution would work in
case you would have only a component, or maybe using some nasty hack,
informing those values inside the component's listener, so they're
available to the page's listener when is called. I think I would
prefer to create my own IActionListener to receive the component as a
parameter insted of doing that. The question is, why is that
information discarded? Is there any cleaner way to do this? Am I
missing anything?

Best regards
Jose

On Mon, 03 Jan 2005 22:02:03 +0100, Mikaël Cluseau <nw...@nwrk.dyndns.org> wrote:
> The code I gave in the previous thread did this :
> 
> [EditPage.java]
> public void performCallback(IRequestCycle cycle) {
>     IPage page = cycle.getPage(getComponentPage());
>     cycle.activate(page);
>     // This gets the component from its recorded path
>     Component component = (Component)
>             page.getNestedComponent(getComponentPath());
>     component.triggerListener(cycle); // << I forgot "Listener" here...
> }
> 
> The only I didn't do is to rewind the page until the original component
> that triggered the action (something like cycle.rewindComponent(), but I
> don't remember), so the component's context is not restored (you need
> this if you have a loop as I understand things).
> 
> If you want to access your component (like to get one of its values) I
> think that the triggered action should be in the component, since it
> looks like component's specific behaviour. Otherwise, you need to define
> an interface or root page class and call the right method from it
> (ugly?).
> 
> Mikael.
> 
> Le lundi 03 janvier 2005 à 13:45 +0100, Jose Gonzalez Gomez a écrit :
> > The code in ListenerMap.SyntheticListener seems to discard this information:
> >
> > private void invoke(IRequestCycle cycle)
> > {
> >     Object[] args = new Object[] { cycle };
> >
> >     invokeTargetMethod(_target, _method, args);
> > }
> >
> > public void actionTriggered(IComponent component, IRequestCycle cycle)
> > {
> >     invoke(cycle);
> > }
> >
> > I don't understand why this information is discarded, as I think
> > accessing the source of an event would be desirable in some cases. I
> > guess the only solution, if I want to access the source component, is
> > to write my own IActionListener. Am I missing anything?
> >
> > Best regards
> > Jose
> >
> >
> > On Mon, 3 Jan 2005 13:13:27 +0100, Jose Gonzalez Gomez
> > <jg...@gmail.com> wrote:
> > > Another question... if you want to create a listener in a page or
> > > component, you just have to create a method with the following
> > > signature:
> > >
> > > public void myListener( IRequestCycle cycle)
> > >
> > > but in IActionListener you have the following method:
> > >
> > > void actionTriggered(IComponent component, IRequestCycle cycle)
> > >
> > > where component is the component that fired the event. Is there any
> > > way to access that component in the myListener method? Should I write
> > > a listener class to be able to access the component?
> > >
> > > Thanks in advance, best regards
> > > Jose
> > >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
>

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


Re: Accessing component that fired event in listener

Posted by Mikaël Cluseau <nw...@nwrk.dyndns.org>.
The code I gave in the previous thread did this :

[EditPage.java]
public void performCallback(IRequestCycle cycle) {
    IPage page = cycle.getPage(getComponentPage());
    cycle.activate(page);
    // This gets the component from its recorded path
    Component component = (Component)
            page.getNestedComponent(getComponentPath());
    component.triggerListener(cycle); // << I forgot "Listener" here...
}

The only I didn't do is to rewind the page until the original component
that triggered the action (something like cycle.rewindComponent(), but I
don't remember), so the component's context is not restored (you need
this if you have a loop as I understand things).

If you want to access your component (like to get one of its values) I
think that the triggered action should be in the component, since it
looks like component's specific behaviour. Otherwise, you need to define
an interface or root page class and call the right method from it
(ugly?).

Mikael.

Le lundi 03 janvier 2005 à 13:45 +0100, Jose Gonzalez Gomez a écrit :
> The code in ListenerMap.SyntheticListener seems to discard this information:
> 
> private void invoke(IRequestCycle cycle)
> {
>     Object[] args = new Object[] { cycle };
> 
>     invokeTargetMethod(_target, _method, args);
> }
> 
> public void actionTriggered(IComponent component, IRequestCycle cycle)
> {
>     invoke(cycle);
> }
> 
> I don't understand why this information is discarded, as I think
> accessing the source of an event would be desirable in some cases. I
> guess the only solution, if I want to access the source component, is
> to write my own IActionListener. Am I missing anything?
> 
> Best regards
> Jose
> 
> 
> On Mon, 3 Jan 2005 13:13:27 +0100, Jose Gonzalez Gomez
> <jg...@gmail.com> wrote:
> > Another question... if you want to create a listener in a page or
> > component, you just have to create a method with the following
> > signature:
> > 
> > public void myListener( IRequestCycle cycle)
> > 
> > but in IActionListener you have the following method:
> > 
> > void actionTriggered(IComponent component, IRequestCycle cycle)
> > 
> > where component is the component that fired the event. Is there any
> > way to access that component in the myListener method? Should I write
> > a listener class to be able to access the component?
> > 
> > Thanks in advance, best regards
> > Jose
> >


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


Re: Accessing component that fired event in listener

Posted by Jose Gonzalez Gomez <jg...@gmail.com>.
The code in ListenerMap.SyntheticListener seems to discard this information:

private void invoke(IRequestCycle cycle)
{
    Object[] args = new Object[] { cycle };

    invokeTargetMethod(_target, _method, args);
}

public void actionTriggered(IComponent component, IRequestCycle cycle)
{
    invoke(cycle);
}

I don't understand why this information is discarded, as I think
accessing the source of an event would be desirable in some cases. I
guess the only solution, if I want to access the source component, is
to write my own IActionListener. Am I missing anything?

Best regards
Jose


On Mon, 3 Jan 2005 13:13:27 +0100, Jose Gonzalez Gomez
<jg...@gmail.com> wrote:
> Another question... if you want to create a listener in a page or
> component, you just have to create a method with the following
> signature:
> 
> public void myListener( IRequestCycle cycle)
> 
> but in IActionListener you have the following method:
> 
> void actionTriggered(IComponent component, IRequestCycle cycle)
> 
> where component is the component that fired the event. Is there any
> way to access that component in the myListener method? Should I write
> a listener class to be able to access the component?
> 
> Thanks in advance, best regards
> Jose
>

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