You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Nathan Quirynen <na...@pensionarchitects.be> on 2021/10/27 18:38:39 UTC

Trigger event to outer component

Hi,

I want to bubble up an event from a component, which is deeply nested in 
other components, to an outer component, but it only bubbles up to the 
page and not further to the component defined as t:type="***" in the page.

Some simplified example code to clarify:


Page:

<html t:type="layout" ...>
     ...
     <t:deeplynestedcomponent />
     ...
</html>


DeeplyNestedComponent:

componentResources.triggerEvent("someEvent", null, null);


Following works up to the Page class, but not if I add it in the Layout 
component:

@OnEvent(value = "someEvent")
void doSomething() {}


Is there anyway to catch this event in the Layout component?



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


Re: Trigger event to outer component

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Thu, Oct 28, 2021 at 1:26 PM Nathan Quirynen <na...@pensionarchitects.be>
wrote:

> Thank you for your reply.
>

My pleasure to (at least try to) help!


> Are you sure this should work as I thought it would? I just cannot get
> it to work even in a simple case.
>

I've given some more thought to it and I discovered I was wrong. It
shouldn't work. The component triggering the event isn't actually a Layout
child, since the former wasn't declared inside the latter's template, and
that explains why the event isn't triggered there. It's instead a direct
page child. You can catch the event on the page and trigger a similar one
to Layout by using componentResources.getEmbeddedComopnent("layout" /* t:id
value */).getComponentResources().triggerEvent(...).


> PS: Tapestry version 5.7.1
>

You should definitely upgrade to 5.7.3 due to a couple of security fixes,
by the way.


>
> Op 28/10/2021 om 15:44 schreef Thiago H. de Paula Figueiredo:
> > Hello!
> >
> > Events do bubble up in the component hierarchy/tree until they're
> handled,
> > so the situation is a bit weird. Have you checked whether there's some
> > other component in between which is catching this event and thereby
> > avoiding Layout from receiving it?
> >
> > On Wed, Oct 27, 2021 at 3:38 PM Nathan Quirynen <
> nathan@pensionarchitects.be>
> > wrote:
> >
> >> Hi,
> >>
> >> I want to bubble up an event from a component, which is deeply nested in
> >> other components, to an outer component, but it only bubbles up to the
> >> page and not further to the component defined as t:type="***" in the
> page.
> >>
> >> Some simplified example code to clarify:
> >>
> >>
> >> Page:
> >>
> >> <html t:type="layout" ...>
> >>       ...
> >>       <t:deeplynestedcomponent />
> >>       ...
> >> </html>
> >>
> >>
> >> DeeplyNestedComponent:
> >>
> >> componentResources.triggerEvent("someEvent", null, null);
> >>
> >>
> >> Following works up to the Page class, but not if I add it in the Layout
> >> component:
> >>
> >> @OnEvent(value = "someEvent")
> >> void doSomething() {}
> >>
> >>
> >> Is there anyway to catch this event in the Layout component?
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >>
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

-- 
Thiago

Re: Trigger event to outer component

Posted by Nathan Quirynen <na...@pensionarchitects.be>.
Thank you for your reply.

I have just made a simple test case in my testing Tapestry project to 
avoid other possible handlers as you suggested could exist:

A page class which contains a component that triggers an event using 
componentResources and the page class uses t:type="layout".
But again I have the same behaviour; the event can be handled in the 
page class, but not in the layout component.

Are you sure this should work as I thought it would? I just cannot get 
it to work even in a simple case.

PS: Tapestry version 5.7.1

Op 28/10/2021 om 15:44 schreef Thiago H. de Paula Figueiredo:
> Hello!
>
> Events do bubble up in the component hierarchy/tree until they're handled,
> so the situation is a bit weird. Have you checked whether there's some
> other component in between which is catching this event and thereby
> avoiding Layout from receiving it?
>
> On Wed, Oct 27, 2021 at 3:38 PM Nathan Quirynen <na...@pensionarchitects.be>
> wrote:
>
>> Hi,
>>
>> I want to bubble up an event from a component, which is deeply nested in
>> other components, to an outer component, but it only bubbles up to the
>> page and not further to the component defined as t:type="***" in the page.
>>
>> Some simplified example code to clarify:
>>
>>
>> Page:
>>
>> <html t:type="layout" ...>
>>       ...
>>       <t:deeplynestedcomponent />
>>       ...
>> </html>
>>
>>
>> DeeplyNestedComponent:
>>
>> componentResources.triggerEvent("someEvent", null, null);
>>
>>
>> Following works up to the Page class, but not if I add it in the Layout
>> component:
>>
>> @OnEvent(value = "someEvent")
>> void doSomething() {}
>>
>>
>> Is there anyway to catch this event in the Layout component?
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>

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


Re: Trigger event to outer component

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Hello!

Events do bubble up in the component hierarchy/tree until they're handled,
so the situation is a bit weird. Have you checked whether there's some
other component in between which is catching this event and thereby
avoiding Layout from receiving it?

On Wed, Oct 27, 2021 at 3:38 PM Nathan Quirynen <na...@pensionarchitects.be>
wrote:

> Hi,
>
> I want to bubble up an event from a component, which is deeply nested in
> other components, to an outer component, but it only bubbles up to the
> page and not further to the component defined as t:type="***" in the page.
>
> Some simplified example code to clarify:
>
>
> Page:
>
> <html t:type="layout" ...>
>      ...
>      <t:deeplynestedcomponent />
>      ...
> </html>
>
>
> DeeplyNestedComponent:
>
> componentResources.triggerEvent("someEvent", null, null);
>
>
> Following works up to the Page class, but not if I add it in the Layout
> component:
>
> @OnEvent(value = "someEvent")
> void doSomething() {}
>
>
> Is there anyway to catch this event in the Layout component?
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

-- 
Thiago