5 Replies Latest reply on Oct 6, 2011 7:41 AM by jaikiran

    lookup a managed bean

    paul.setzermann

      Hey all,

       

      Is it possible to lookup a @ManagedBean in a helper class?

      I tried something like the following but it is not working (->NamingExeption):

       

      InitialContext ic = null;
      try {
           ic = new InitialContext();
           SearchView searchView = (SearchView)ic.lookup("java:module/searchView");
      
      } catch (NamingException e) {
           e.printStackTrace();
      }
      
      
      

      I also tried:

      Name of my .war: AnnotationDatabase

         ...lookup("java:app/AnnotationDatabase/searchView")
         ...lookup("java:global/AnnotationDatabase/searchView")
      

       

       

      SearchView:

       

      @ManagedBean(name="searchView")
      @SessionScoped
      public class SearchView implements Serializable {
      ...
      }
      

       

       

      Thanks and Cheers,

      Paul

        • 1. Re: lookup a managed bean
          morphy

          you are forcing helper classes to be JEE dependant... it is not the answer to your question but you have probably to re-model your... model...

          another non-answer is that ManagedBeans are presentation and you should avoid business logic in their method... move the logic in an EJB, it becomes reusable even in your helper classes... sorry if it is out of scope but i have too much pains in the neck for logic in the presentation tier that i cannot shut up...

          • 2. Re: lookup a managed bean
            paul.setzermann

            Hey Riccardo,

             

            thanks for your comment.

            I see what you mean and I think the same way. But in this special case I don't have another option (not exactly true) .

            Maybe I find another solution for this problem.

            Thank you anyway.

             

            Cheers

            • 3. Re: lookup a managed bean
              paul.setzermann

              Do you possibly know a common solution to refresh a SessionScoped View after database entries have changed!?

              • 4. Re: lookup a managed bean
                morphy

                which is your need? provide some kind of alerts in the user interface about persistent data changes?

                • 5. Re: lookup a managed bean
                  jaikiran

                  By the way, JSF managed beans are not bound to JNDI.