Hi Daniel,

This pattern is generally called a "view controller".

The Apache Shale project has provided this for several years:
  http://shale.apache.org/shale-view/index.html

The MyFaces Orchestra project also provides a "view controller"
framework.

And the code Andrew links to is also a kind of "view controller",
although limited to just one function: "run logic before view".

I'm pretty sure that JBoss Seam also provides this kind of thing.

It is a shame that this isn't part of the JSF core, and maybe in future
it will be.

The problem in all cases is defining what logic will run for which
views. Shale and Orchestra have a default approach of looking for a
managed-bean whose name "matches" the view-id, although both can be
configured in various ways. Andrew's code uses a configuration file to
map viewid->action. I'm not sure what Seam does.

They are all valid ways of dealing with this problem. And most of them
actually use a PhaseListener to implement their logic.

Of course if you don't need to support the ability to navigate off to
some other page, then the simplest solution is just to put a component
at the top of each page that invokes the logic you want.

Regards,

Simon



On Mon, 2008-01-07 at 14:33 -0700, Andrew Robinson wrote:
> See my response. The simplest component is the jsf-comp one that I
> wrote:
> 
> http://jsf-comp.sourceforge.net/components/onload/index.html
> 
> 
> On Jan 7, 2008 2:26 PM, daniel ccss <[EMAIL PROTECTED]> wrote:
>         Thanks for the answers, I used a phaselistener but is for all
>         the application, like the one in the example of the login:
>          
>          
> <phase-listener>com.loffler.copycenter.controller.LoggedInCheck</phase-listener>
>         
>         but this type of listener is call for every Bean and my case
>         is different.
>          
>         Let me explain better my case, I have an App1 and App2, they
>         are in different servers, App1 have a link to call the App2,
>         but I need do some things before show the index of the App1,
>         actually the link calls directly the index.jsp of the App1, In
>         this case I only need the listener for do things when the App1
>         calls App2, something like in the onload of the app2. Can I
>         use a listener when a specific JSP is show? Can I call
>         directly the backing bean?
>          
>         thanks
>         
>          
>         
>          
>         On Jan 7, 2008 2:53 PM, John Carlson <[EMAIL PROTECTED]>
>         wrote:
>                 Can you do it in Spring?
>                 
>                 John  
>                 
>                 
>                 
>                 At 12:24 PM 1/7/2008, you wrote:
>                 
>                 > Hi all,
>                 > 
>                 > In struts:
>                 > I can call a JSP page like
>                 > http://..../JSP/Example.jsp and I also can call an
>                 > action that do something and then do the forward to
>                 > the Example.jsp like this: http:// .../Example.do
>                 > 
>                 > In JSF:
>                 > I can call a JSP page like
>                 > http://...faces/JSP/Example.jsp but there is a way
>                 > to call a backing bean before show the JSP?
>                 > 
>                 > I need to do something in the backing bean (set some
>                 > variables, etc) before showing the jsp, but I dont
>                 > know if this is posible in JSF. 
>                 > 
>                 > thanks
>         
>         
> 

Reply via email to