In GuiceResolver managed-bean-scope is ignored, scope defaults to none
----------------------------------------------------------------------
Key: MYFACES-1999
URL: https://issues.apache.org/jira/browse/MYFACES-1999
Project: MyFaces Core
Issue Type: Bug
Components: JSR-252
Affects Versions: 1.2.4
Environment: Tomcat 6
Reporter: Tony Robertson
Priority: Minor
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.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.