Uploaded image for project: 'MyFaces Core'
  1. MyFaces Core
  2. MYFACES-1999

In GuiceResolver managed-bean-scope is ignored, scope defaults to none

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Won't Fix
    • 1.2.4
    • None
    • JSR-252
    • None
    • Tomcat 6

    Description

      The problem with the current org.apache.myfaces.el.unified.resolver.GuiceResolver is that it doesn't take into account the managed-bean-scope from the ManagedBean configuration. Typically you end up with multiple instances of the managed bean (a new one every time the resolver is called) – ie, same as a managed-bean-scope of "none".

      Note, there is some code in the resolver like this:
      if (ectx == null ||
      ectx.getRequestMap().containsKey(property) ||
      ectx.getSessionMap().containsKey(property) ||
      ectx.getApplicationMap().containsKey(property) )
      return null;
      This works if there is already a request, session or application scope attribute with the given name, but if not, the managed bean is not added to the scope. You can see that the overriden "getValue" method from the ManagedBeanResolver was actually responsible for putting any new object into the scope via the "putInScope" method.

      The simplest way to fix this in the code seems to be to make the ManagedBeanResolver.putInScope method "protected" (rather than private), and then call it from the GuiceResolver.getValue method whenever a new value is obtained from the injector.

      Meanwhile, a work-around is to leverage the guice-servlet module and then to specify the scope in the guice module, something like this:
      bind(HelloWorldBacking.class).in(ServletScopes.REQUEST);
      However, for that you have to list all your managed beans in two places (faces-config.xml as well as your guice module), and also have to add the com.google.inject.servlet.GuiceFilter filter class to your web app.

      Attachments

        Activity

          People

            Unassigned Unassigned
            tony_robertson Tony Robertson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: