3

WI have a question about the "Best Practice" Design for controller beans.

I was reading this very good question and the linking article:

Question "JSF backing bean structure (best practices)" Scoping Best Practice

Online Article Distinctions between different kinds of JSF Managed-beans

My question is concerning the controller bean. I'm using JSF / Spring and was wondering why I would want to use request scope for Controller beans?

The controller logic being defined as "...execute some kind of business logic and return navigation outcome.." I would think doesn't require a request scope but either session/application scope. Why keep creating those controller objects on every request?

In my case I would create the controller bean in the faces-config obviously and inject it with my managed properties through spring.

Thoughts please around the scoping? Thanks.

Clarification: Using JSF 1.2, Spring 3. Using faces-config.xml to declare my beans. Not through annotations.

8
  • Related: Distinction between different types of managed beans Commented Sep 26, 2011 at 15:47
  • Thanks for the additional article BalusC. So if you had a Controller class who purpose was to support business logic, would their be anything wrong you think in making that application scope? Commented Sep 26, 2011 at 17:15
  • If the controller contains a model representing request/session scoped data, then definitely yes. It would clash in multiple requests/sessions. Commented Sep 26, 2011 at 17:17
  • Ok but if the controller was more like a static class that performed the business logic but didn't need a modal as a instance variable in it, it would be fine. Commented Sep 26, 2011 at 17:35
  • That should then not be a @ManagedBean, but a @Stateless EJB (or whatever Spring offers to supplant EJB, I don't do Spring, so I can't go in detail) which you inject in your real @ManagedBean. Commented Sep 26, 2011 at 17:50

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.