[prev in list] [next in list] [prev in thread] [next in thread] 

List:       struts-user
Subject:    Re: struts-faces
From:       "Craig R. McClanahan" <craigmcc () apache ! org>
Date:       2003-09-18 16:32:35
[Download RAW message or body]

On Thu, 18 Sep 2003, Ted Husted wrote:

> Date: Thu, 18 Sep 2003 07:05:44 -0400
> From: Ted Husted <husted@apache.org>
> Reply-To: Struts Users Mailing List <struts-user@jakarta.apache.org>
> To: Struts Users Mailing List <struts-user@jakarta.apache.org>
> Subject: Re: struts-faces
>
> Craig R. McClanahan wrote:
>  >     // Return an Action for processing a logon
>  >     public Action getLogon() {
>  >       return new Action() {
>  >         public String invoke() {
>  >           return logon();
>  >         }
>  >       }
>  >     }
>  >
>
> Very cool technique =:)
>

Anonymous inner classes have some mind-bending capabilities :-).

> But this has to be the coolest trick yet:
>
>  >         // Add an error message
>  >         FacesContext.getCurrentInstance().addMessage(...);
>
> Hey, why bother passing around a context when you can get the thread to
> do it? Quite fancy =:)

It's definitely cute, but there's a tradeoff.  The FacesContext
implementation has to use a ThreadLocal variable (or something equivalent)
in order to keep trace of the current FacesContext instance for each
webapp, so there's a (small but real) performance difference between
calling getCurrentInstance() and passing the current context on the stack.
In general, we have tried to pass the context when it was easily
available, but not stressed over using getCurrentInstance() in other
cases.

One might think about applying this design pattern to something like
commons-chain as well (to avoid passing on the Context object).  That
would work if there was only one chain being processed per thread, which
may or may not be practical (it is for JavaServer Faces because there's
only one FacesContext instance per request processing thread).

>
> http://java.sun.com/webservices/docs/1.2/api/javax/faces/context/FacesContext.html
>
> -Ted.

Craig

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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic