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.

Community
  • 1
  • 1
haju
  • 1,278
  • 4
  • 20
  • 38
  • Related: [Distinction between different types of managed beans](http://stackoverflow.com/questions/7223055/distinction-between-different-types-of-managed-beans) – BalusC Sep 26 '11 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? – haju Sep 26 '11 at 17:15
  • If the controller contains a model representing request/session scoped data, then definitely yes. It would clash in multiple requests/sessions. – BalusC Sep 26 '11 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. – haju Sep 26 '11 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`. – BalusC Sep 26 '11 at 17:50
  • really, an EJB. Interesting. Why is that? – haju Sep 26 '11 at 17:50
  • Nevermind this. I forgot that you're using Spring. Read "Spring controller" instead of EJB. – BalusC Sep 26 '11 at 17:52
  • Just added a edit at the end to clairfy what I am using. – haju Sep 26 '11 at 17:58

0 Answers0