This week's giveaway is in the Threads forum.
We're giving away four copies of Java Concurrency Live Lessons and have Doug Schmidt on-line!
See this thread for details.
Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Create a managed bean per view  RSS feed

 
Jorge Martinez
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hy,

About creating views,

1. When we have a view and this uses two or three managed beans and not only one, is this ok? is a good design?

2 If we have two views and both of them only share one functionality (they need to display datatable with clients) , for the second view and for the shared functionality, should I in the managed bean for the second view create the same method that gets the clients or reuse the method in the managed bean created for the first view?

Thanks
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Model/View/Controller (MVC) is flexible. One View can reference multiple Models, one Model can be bound to multiple Views. It's a many-to-many correspondence.

Typically, a single backing bean will contain the UI Model for a single View, but that's just because it's convenient. A single managed bean can be used as the accumulator for a series of Views if you are doing a Wizard-style workflow, you might have an application-scoped backing bean for the SelectItem list on a View so that a single copy of the menu list is shared between multiple users. And so forth. Whatever works best for the job at hand.
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also put commonly used code in utility classes so that you don't have to depend on beans just to get at some code.
You haven't mentioned the scopes of your beans in your question which is important because that determines when the beans are (re)created and destroyed.
You also have new scopes in the latest JSF versions for dealing with ViewScopes and FlowScopes. So as mentioned, depending on the exact scenario you are dealing with some approaches will be more optimal than others.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!