0

How can I get all the initialized managed beans in the session? Following code crashes the JVM every time.

FacesContext facesContext=FacesContext.getCurrentInstance();
com.sun.faces.application.ApplicationAssociate application = 
ApplicationAssociate.getInstance(facesContext.getExternalContext());
Shahzeb
  • 4,745
  • 4
  • 27
  • 40
  • Can't you use the jconsole? That is what I use when searching for running beans – jlengrand May 16 '12 at 09:16
  • I actually need to get them through the code. – Shahzeb May 16 '12 at 09:19
  • you want to get one session scope bean in another one ? use managedproperty... – Daniel May 16 '12 at 09:20
  • No @Daniel I do not need to inject them not talking about `managedproperty` I need to know with one bean all the beans that are with in that same session . Basically there is a method in these beans so those beans that are in the session I need to access them and call that method and let go . – Shahzeb May 16 '12 at 09:23
  • 1
    ow, haven't read the title properly... another approach is to insert the session bean into a list that will be maintained by the application scope bean , and iterate over them... but then you need to maintain it... – Daniel May 16 '12 at 10:48
  • @Daniel yes thats a good idea too . Have upvoted your comment :) – Shahzeb May 16 '12 at 23:46

1 Answers1

1

Can't you use something like

 FacesContext context = FacesContext.getCurrentInstance();
 HttpSession session = (HttpSession) context.getExternalContext().getSession(true);
 Enumeration mySessionBeans = session.getAttributeNames();
Petr Mensik
  • 26,874
  • 17
  • 90
  • 115