You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Andreas Pardeike <fs...@gmail.com> on 2009/09/28 15:27:54 UTC

Event bubbling - how to implement a top level catch-all target

Hi,

My application uses a base class that catches all events that are
not handled by a component or a page on the way up.

At first, I tried to write the handler in my layout component but
since its not the top of the hierarchy, I had to create a base class
that every page extends. There, I have my generic event handler
and it works fine.

But I don't like the concept that all my pages have to extend
that base class and here comes my question:

Is there any other way to configure Tapestry 5.1 so that unhandled
events get processed in a generic way (like a custom dispatcher)?

If possible, it would make my event handling so much better.
Regards,
Andreas Pardeike

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


Re: Event bubbling - how to implement a top level catch-all target

Posted by Massimo Lusetti <ml...@gmail.com>.
On Tue, Sep 29, 2009 at 11:24 PM, Andreas Pardeike <fs...@gmail.com> wrote:

> How can I make sure that information from component construction time will
> survive so it can be used when the ajax event is processed?

That's how things works, currently. It's a task for your "service" to
provide that.

Cheers
-- 
Massimo
http://meridio.blogspot.com

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


Re: Event bubbling - how to implement a top level catch-all target

Posted by Andreas Pardeike <fs...@gmail.com>.
On 29 sep 2009, at 16.12, Thiago H. de Paula Figueiredo wrote:

>> One simple question related to this: if I have a service that is  
>> used by
>> many components and that holds a list of component related  
>> information,
>> how do I make this request related?
>
> Your service must have the perthread scope. A new instance will be  
> created for each request, as each one is served by one thread.
> More details at http://tapestry.apache.org/tapestry5.1/tapestry-ioc/service.html 
> , section Defining Service Scope.

Great! I missed that part of the docs. Unfortunately, I get a problem
with the component render cycle. Right now, in my test case, a component
registers with the service within the afterRender() phase and this will
trigger the creation of my per-thread service. So far, so good.

Now, when I click on one of my test ajax action links, my custom  
component
event handler filter routes the event to my service but since this is a
new request, it already has been freed and will be created again.

How can I make sure that information from component construction time  
will
survive so it can be used when the ajax event is processed?

/Andreas

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


Re: Event bubbling - how to implement a top level catch-all target

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Tue, 29 Sep 2009 11:08:01 -0300, Andreas Pardeike <fs...@gmail.com>  
escreveu:

> Thanks for the reply Thiago.

You're welcome! :)

> One simple question related to this: if I have a service that is used by
> many components and that holds a list of component related information,
> how do I make this request related?

Your service must have the perthread scope. A new instance will be created  
for each request, as each one is served by one thread.
More details at  
http://tapestry.apache.org/tapestry5.1/tapestry-ioc/service.html, section  
Defining Service Scope.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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


Re: Event bubbling - how to implement a top level catch-all target

Posted by Andreas Pardeike <fs...@gmail.com>.
Thanks for the reply Thiago.

One simple question related to this: if I have a service that is used by
many components and that holds a list of component related information,
how do I make this request related? That is, if I want i.e. have a list
of all those components nested ids for a given request (they send that  
when
they register themselves at beginRender) then how do I clear that list  
at
the beginning or end of the request inside the service? How do I make  
sure
that I keep that information request relative since the service is a  
singleton.

Thanks,
Andreas Pardeike


On 29 sep 2009, at 16.00, Thiago H. de Paula Figueiredo wrote:

> Em Tue, 29 Sep 2009 03:21:40 -0300, Andreas Pardeike <fsys.dev@gmail.com 
> > escreveu:
>
>> Thiago,
>
> Hi!
>
>> I have a test version up in a project and I wonder why Tapestry
>> does not support this kind of loose event handling where
>> components register themselves for zone refreshes or method calls
>> that are related to events.
>
> I guess that's because loose event handling is against Tapestry's  
> philosophy to not be loose and provide a very robust error checking.
>
> I think you can implement what you want overriding some service.
>
>> I find that essential to implement
>> i.e. a global refresh zone strategy where a login component
>> triggers a 'logged in' event and where other components subscribe
>> to such an event because they have a zone that needs to refresh
>> to display a different price. It would also provide a much looser
>> connection between two less related components.
>
> AFAIK, Tapestry, as it is now, doesn't support more than one handler  
> for the same event isntance.
>
> Have you taken a look at MultiZoneUpdate? I guess it solves what you  
> want at least partly.
>
> -- 
> Thiago H. de Paula Figueiredo
> Independent Java consultant, developer, and instructor
> http://www.arsmachina.com.br/thiago
>
> ---------------------------------------------------------------------
> 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: Event bubbling - how to implement a top level catch-all target

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Tue, 29 Sep 2009 03:21:40 -0300, Andreas Pardeike <fs...@gmail.com>  
escreveu:

> Thiago,

Hi!

> I have a test version up in a project and I wonder why Tapestry
> does not support this kind of loose event handling where
> components register themselves for zone refreshes or method calls
> that are related to events.

I guess that's because loose event handling is against Tapestry's  
philosophy to not be loose and provide a very robust error checking.

I think you can implement what you want overriding some service.

> I find that essential to implement
> i.e. a global refresh zone strategy where a login component
> triggers a 'logged in' event and where other components subscribe
> to such an event because they have a zone that needs to refresh
> to display a different price. It would also provide a much looser
> connection between two less related components.

AFAIK, Tapestry, as it is now, doesn't support more than one handler for  
the same event isntance.

Have you taken a look at MultiZoneUpdate? I guess it solves what you want  
at least partly.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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


Re: Event bubbling - how to implement a top level catch-all target

Posted by Andreas Pardeike <fs...@gmail.com>.
Thiago,

Actually, an error page is not what I want. I want to implement
a message center (I call it switchboard) that distributes events
and takes care of cross-component zone updates.

I have a test version up in a project and I wonder why Tapestry
does not support this kind of loose event handling where
components register themselves for zone refreshes or method calls
that are related to events. I find that essential to implement
i.e. a global refresh zone strategy where a login component
triggers a 'logged in' event and where other components subscribe
to such an event because they have a zone that needs to refresh
to display a different price. It would also provide a much looser
connection between two less related components.

I need to polish this a bit and are willing to commit this to the
community as plug-in to tapestry because I find it very generic
and essential. It's a natural extension to event-bubbling that
otherwise only provides a one-way (up in this case) communication.

/Andreas Pardeike


On 28 sep 2009, at 16.27, Thiago H. de Paula Figueiredo wrote:

> Em Mon, 28 Sep 2009 10:41:35 -0300, Cordenier Christophe <Christophe.Cordenier@atosorigin.com 
> > escreveu:
>
>> Hi
>
> Hi!
>
>> Take a look ComponentEventRequestHandlerImpl, following code are  
>> calling the event on requested Component and Event :
>>
>> boolean handled = element.triggerContextEvent 
>> (parameters.getEventType(), parameters.getEventContext(),
>>                                                      callback);
>> if (!handled)
>>        throw new TapestryException(ServicesMessages.eventNotHandled 
>> (element, parameters.getEventType()), element, null);
>
> You can catch these exceptions in an error page. Its name is defined  
> by the tapestry.exception-report-page configuration symbol. Make  
> sure your page implements ExceptionReporter, so it can receive the  
> raised exception.
>
> -- 
> Thiago H. de Paula Figueiredo
> Independent Java consultant, developer, and instructor
> http://www.arsmachina.com.br/thiago

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


Re: Event bubbling - how to implement a top level catch-all target

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Mon, 28 Sep 2009 10:41:35 -0300, Cordenier Christophe  
<Ch...@atosorigin.com> escreveu:

> Hi

Hi!

> Take a look ComponentEventRequestHandlerImpl, following code are calling  
> the event on requested Component and Event :
>
> boolean handled = element.triggerContextEvent(parameters.getEventType(),  
> parameters.getEventContext(),
>                                                       callback);
> if (!handled)
>         throw new  
> TapestryException(ServicesMessages.eventNotHandled(element,  
> parameters.getEventType()), element, null);

You can catch these exceptions in an error page. Its name is defined by  
the tapestry.exception-report-page configuration symbol. Make sure your  
page implements ExceptionReporter, so it can receive the raised exception.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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


RE: Event bubbling - how to implement a top level catch-all target

Posted by Cordenier Christophe <Ch...@atosorigin.com>.
Hi

Since not handled event are considered as error, an exception is thrown when event is not handled. I think you can catch it in a ComponentEventRequestFilter instance.

Take a look ComponentEventRequestHandlerImpl, following code are calling the event on requested Component and Event :

boolean handled = element.triggerContextEvent(parameters.getEventType(), parameters.getEventContext(),
                                                      callback);
if (!handled)
        throw new TapestryException(ServicesMessages.eventNotHandled(element, parameters.getEventType()), element,
                                        null);

I Hope this helps,
Christophe.

-----Message d'origine-----
De : Andreas Pardeike [mailto:fsys.dev@gmail.com]
Envoyé : lundi 28 septembre 2009 15:28
À : Tapestry users
Objet : Event bubbling - how to implement a top level catch-all target

Hi,

My application uses a base class that catches all events that are
not handled by a component or a page on the way up.

At first, I tried to write the handler in my layout component but
since its not the top of the hierarchy, I had to create a base class
that every page extends. There, I have my generic event handler
and it works fine.

But I don't like the concept that all my pages have to extend
that base class and here comes my question:

Is there any other way to configure Tapestry 5.1 so that unhandled
events get processed in a generic way (like a custom dispatcher)?

If possible, it would make my event handling so much better.
Regards,
Andreas Pardeike

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




Ce message et les pièces jointes sont confidentiels et réservés à l'usage exclusif de ses destinataires. Il peut également être protégé par le secret professionnel. Si vous recevez ce message par erreur, merci d'en avertir immédiatement l'expéditeur et de le détruire. L'intégrité du message ne pouvant être assurée sur Internet, la responsabilité du groupe Atos Origin ne pourra être recherchée quant au contenu de ce message. Bien que les meilleurs efforts soient faits pour maintenir cette transmission exempte de tout virus, l'expéditeur ne donne aucune garantie à cet égard et sa responsabilité ne saurait être recherchée pour tout dommage résultant d'un virus transmis.

This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Atos Origin group liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted.


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