1

I have three screens(views) associated with separate managed beans for each view. And, I have a common pop-up dialog which can be opened in all the views.

Can I define a managedbean separately for the pop-up with state @NoneScoped; and maintain an instance of it in each parent bean?? or

Do I need to maintain pop-up data in all three parent views?

Please, suggest me the best practice.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Nani
  • 11
  • 2

1 Answers1

1

I think this is what you are looking for (check out the answer by BalusC) -

Whats the correct way to create multiple instances of managed beans in JSF 2.0

And since you are using @NoneScoped (unlike @RequestScoped in the above question), I also recommend you to look at this answer by BalusC (about @NoneScoped) -

what is none scope bean and when to use it?

And according to this answer, you can't maintain any instances of a managedbean that is none-scoped, as they are garbaged as soon as they are used.

So, in your case since you have three separate views, for each view, the bean is constructed and used to build the view and garbaged. (Looks like it does not even last for a request cycle). When you request another view, it will be a separate instance.

To have multiple intances of a bean, you can have three properties in a Session-Scoped been (to make them survive across multiple views).

@ManagedBean 
@SessionScoped 
public class Parent {     
    private Child child1;     
    private Child child2;     
    private Child child3;     

    // ... 
}     
Community
  • 1
  • 1
Bhesh Gurung
  • 50,430
  • 22
  • 93
  • 142
  • Thanks for the answer. Also, provided links are very useful. – Nani Aug 24 '11 at 13:00
  • @Nani: You may accept the answer if you got what you were looking for. I would also suggest (only if you are using jsf 2.0) you to add the tag `jsf 2.0` so that you get more people to view and answer you question. – Bhesh Gurung Aug 24 '11 at 14:42
  • To give more clarity on my question, I have 3 views; and one common popup. Presume, Parent Managed Beans(Parent1, Parent2, Parent3); If I use Child(popup) instanace in each managed bean, then how can I bind variables in the common popup(xhtml)? – Nani Aug 25 '11 at 07:43
  • @Nani: Did you go to the first link and read the answer? Why do you actually want to maintain three separate instances of the Parent bean? – Bhesh Gurung Aug 25 '11 at 16:28
  • Parent1 describes about BenzCar (ViewScreen1), Parent2 describes about VolkswagenCar (ViewScreen2). To display technical specification (Popup) for each Car; The Specification attribute names are same but, the values will be different for each car. How Can I use one common popup to two? – Nani Aug 26 '11 at 07:09