Announcement Announcement Module
Collapse
No announcement yet.
New Scope "none" or "factory" Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • New Scope "none" or "factory"

    I'm currently attempting to convert my JSF managed bean facilities to Spring scoped beans. One thing that I believe Spring scoped beans provides over JSF managed beans is the ability to inject a request scoped bean into a session managed bean while not having the request scope being swallowed up by the session scope.

    This functionality almost opens up the ability to in inject any scoped bean into any other. However, I see 1 more scope type that will be needed in order to inject any kind of bean into a session scoped bean. This scope would retrieve a bean instance from the factory on every method invocation.

    Case 1 new instance on every invocation:
    There may be cases where it would be a good idea to inject a FacesContext into a session scoped bean. Because JSF's FacesContext is unique for each request this could not be injected into a session scoped bean. The example below would allow a facesContext to be injected into a session scoped bean and the faces context would always be the correct facesContext for the given request. This functionality could be provided by scoping the facesContext bean to a request. However, a factory scope would be a more true and generic scoping for this example.

    Example:
    <bean id="facesContext" class="javax.faces.context.FacesContext" factoryMethod="currentInstance" singleton="false">
    <aop:scope type="factory"/>
    </bean>

    <bean id="sessionUIBean" class="ExampleBean">
    <property name="facesContext" ref="facesContext"/>
    <aop:scope type="session"/>
    </bean>

    Case 2 injecting a Spring singleton:
    It would be very useful to inject singletons into a session scoped bean. Currently a singleton cannot be injected into a session scoped bean because a session bean can be serialized creating 2 instances of the singleton among other problems. Using the factory scope would allow a singleton to be injected into any scope that may need to be serialized.

    Example:
    <bean id="myLogic" class="dbLogic" singleton="true">
    <aop:scope type="factory"/>
    </bean>

    <bean id="sessionUIBean" class="ExampleBean">
    <property name="logic" ref="dbLogic"/>
    <aop:scope type="session"/>
    </bean>

    Does this functionality already exist in some form? I admit my knowledge of the existing TargetSources are limited.

    Mike
Working...
X