[ 
https://issues.apache.org/jira/browse/MYFACES-1999?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12638162#action_12638162
 ] 

Leonardo Uribe commented on MYFACES-1999:
-----------------------------------------


The actual implementation of GuiceResolver theorically is correct. Guice has a 
module for servlets (inside guice-1.0.zip distribution there is a jar called 
guice-servlet.jar), so anyone can use it and integrate with jsf web 
applications. From this point of view, myfaces GuiceResolver just gives a start 
point.

This issue could be seen as an enhancement, but after a lot of time thinking 
about it I'm not very sure about modify its semantic due to backwards 
compatibility.

One way to solve this is create a GuiceScopedResolver that handle this case 
(I'm not sure if this is really necessary). For do that, it is necessary to 
create some other classes used for infrastructure, and use the strategy 3 (the 
last on the previous comment, define beans on faces-config.xml).






> 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: Improvement
>          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.

Reply via email to