AW: Tapestry's Simplicity Blues

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

AW: Tapestry's Simplicity Blues

Marcus.Schulte
I've implemented something very similar a couple of weeks ago. So I'd really
like to see a somewhat cleaner approach. Especially, since I also use my
"Base-Listener" to convert certain "User-Exceptions" into friendly Messages,
I would prefer to get these Exceptions directly instead of having to poke
them out of the ApplicationException. It would be much nicer if the
Tapestry-Listener wrapped around an optional custom Base-Listener rather
than the other way round, as I do it now.
Thanks for the hint with the RedirectException! I completely forgot it, and
you're right, it's a nuisance. I think, one should register a redirection
request with the engine directly.
BTW, I also mark my TA's for rollback when an exception is encountered - Do
you handle this in another place? - just curious.



-----Urspr√ľngliche Nachricht-----
Von: Erik Hatcher [mailto:[hidden email]]
Gesendet: Donnerstag, 12. Mai 2005 01:59
An: Tapestry users
Betreff: Re: Tapestry's Simplicity Blues



On May 11, 2005, at 5:02 PM, Ben Eng wrote:

> On Wed, May 11, 2005 at 11:36:39AM -0400, Erik Hatcher wrote:
>
>>
>> There is not a way to intercept listener method invocations with
>> HiveMind that I know of.  If you know of a way, could you please  
>> share?
>>
>
> You don't like how I implemented events before and after listener
> invocation?
>
>   http://issues.apache.org/jira/browse/TAPESTRY-294

To be honest, I had forgotten about your patch.

Despite being a Tapestry committer, I typically try to solve problems  
without modification to the underlying frameworks (although I have  
usually ended up under the hood of most of the libraries I use).  
I've pasted, below, the hack I've used.

I would prefer if Howard signed off on your approach.  I would think  
a more HiveMind-esque technique would be more to the Tapestry 4.0  
style.  I have no objections to what you've done.  Though I'm not  
sure I'd be able to do what I've done with it, considering the way  
Page/RedirectException are handled.  In your terms my post-listener  
event is fired only if the original listener succeed without thrown  
an exception or if throws Page/RedirectException.  I don't think an  
"after" listener event could be coded in your contribution to do  
that.  Please correct me if I'm wrong.

Throwing of an exception for flow control is something we should  
probably re-architect though.

     Erik


   public ListenerMap getListeners() {
     final ListenerMap orig =  super.getListeners();
     return new ListenerMap() {

       public IActionListener getListener(String name) {
         final IActionListener origListener = orig.getListener(name);
         return new IActionListener() {

           public void actionTriggered(IComponent component,  
IRequestCycle cycle) {
             RuntimeException e = null;
             try {
               origListener.actionTriggered(component, cycle);
             }
             catch (RedirectException re) {
               e = re;
             }
             catch (PageRedirectException pre) {
               e = pre;
             }

             // only Tapestry's two flow control "exceptions" make it  
this far, and then are rethrown
             getDataContext().commitChanges();

             if (e != null) throw e;
           }

         };
       }

       public Collection getListenerNames() {
         return orig.getListenerNames();
       }

       public boolean canProvideListener(String name) {
         return orig.canProvideListener(name);
       }
     };
   }

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: AW: Tapestry's Simplicity Blues

Erik Hatcher

On May 12, 2005, at 2:56 AM, Schulte Marcus wrote:
> BTW, I also mark my TA's for rollback when an exception is  
> encountered - Do
> you handle this in another place? - just curious.

Yes, I have an IMonitor to do that, but that really should be moved  
to my custom IActionListener wrapper now I think.

     Erik


>
>
>
> -----Urspr√ľngliche Nachricht-----
> Von: Erik Hatcher [mailto:[hidden email]]
> Gesendet: Donnerstag, 12. Mai 2005 01:59
> An: Tapestry users
> Betreff: Re: Tapestry's Simplicity Blues
>
>
>
> On May 11, 2005, at 5:02 PM, Ben Eng wrote:
>
>
>> On Wed, May 11, 2005 at 11:36:39AM -0400, Erik Hatcher wrote:
>>
>>
>>>
>>> There is not a way to intercept listener method invocations with
>>> HiveMind that I know of.  If you know of a way, could you please
>>> share?
>>>
>>>
>>
>> You don't like how I implemented events before and after listener
>> invocation?
>>
>>   http://issues.apache.org/jira/browse/TAPESTRY-294
>>
>
> To be honest, I had forgotten about your patch.
>
> Despite being a Tapestry committer, I typically try to solve problems
> without modification to the underlying frameworks (although I have
> usually ended up under the hood of most of the libraries I use).
> I've pasted, below, the hack I've used.
>
> I would prefer if Howard signed off on your approach.  I would think
> a more HiveMind-esque technique would be more to the Tapestry 4.0
> style.  I have no objections to what you've done.  Though I'm not
> sure I'd be able to do what I've done with it, considering the way
> Page/RedirectException are handled.  In your terms my post-listener
> event is fired only if the original listener succeed without thrown
> an exception or if throws Page/RedirectException.  I don't think an
> "after" listener event could be coded in your contribution to do
> that.  Please correct me if I'm wrong.
>
> Throwing of an exception for flow control is something we should
> probably re-architect though.
>
>      Erik
>
>
>    public ListenerMap getListeners() {
>      final ListenerMap orig =  super.getListeners();
>      return new ListenerMap() {
>
>        public IActionListener getListener(String name) {
>          final IActionListener origListener = orig.getListener(name);
>          return new IActionListener() {
>
>            public void actionTriggered(IComponent component,
> IRequestCycle cycle) {
>              RuntimeException e = null;
>              try {
>                origListener.actionTriggered(component, cycle);
>              }
>              catch (RedirectException re) {
>                e = re;
>              }
>              catch (PageRedirectException pre) {
>                e = pre;
>              }
>
>              // only Tapestry's two flow control "exceptions" make it
> this far, and then are rethrown
>              getDataContext().commitChanges();
>
>              if (e != null) throw e;
>            }
>
>          };
>        }
>
>        public Collection getListenerNames() {
>          return orig.getListenerNames();
>        }
>
>        public boolean canProvideListener(String name) {
>          return orig.canProvideListener(name);
>        }
>      };
>    }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]