Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.myfaces.orchestra.viewController.spring
Class SpringViewControllerScope

    java.lang.Object
      org.apache.myfaces.orchestra.conversation.spring.AbstractSpringOrchestraScope
          org.apache.myfaces.orchestra.viewController.spring.SpringViewControllerScope

All Implemented Interfaces:
  ConversationFactory, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.config.Scope, org.springframework.context.ApplicationContextAware

    public class SpringViewControllerScope

extends AbstractSpringOrchestraScope

This hooks into the Spring2.x scope-handling mechanism to provide a dummy scope type which will place a bean configured for it into the same conversation that the current viewController lives in.

To use this, in the spring config file add an element with id=N that defines a spring scope with this class as its controller. Then define managed beans with scope="N". When code references such a bean, then the current "view controller" bean is located (ie the bean handling lifecycle events for the current view), and the instance of the target bean from the same conversation is returned. If no such instance currently exists, then one is created and added to that conversation (even when an instance already exists in a different scope).

Note that this means a bean configured with a scope of this type will actually have a separate instance per conversation.

In particular, this works well with spring aop-proxy, where the proxy looks up the bean on each method call, and so always returns the instance in the conversation associated with the current view.

One use for this is implementing custom JSF converters or validators that access persistent objects. When accessing the database they need to use the same PersistenceContext that the beans handing this view use. Defining the converter using this scope type ensures that this happens.

It is an error (ie an exception is thrown) if a bean of this scope is referenced but there is no "view controller" bean associated with the current view.

Constructor Summary
`SpringViewControllerScope()`

Method Summary
`protected void` | `assertSameScope(String beanName, Conversation conversation)` Verify that the specified conversation was created by this scope object.
`Conversation` | `createConversation(ConversationContext context, String conversationName)`
`String` | `getConversationNameForBean(String beanName)` Find the conversation-controller bean for the current view, then return the conversation that is configured for that controller bean.

Methods inherited from class org.apache.myfaces.orchestra.conversation.spring.AbstractSpringOrchestraScope
`buildBeanName, defineBeanPostProcessors, get, getAdvices, getApplicationContext, getConversationForBean, getConversationId, getExplicitConversationName, getProxy, getRealBean, notifyAccessConversation, registerDestructionCallback, remove, setAdvices, setApplicationContext, setAutoProxy, setBeanFactory`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### SpringViewControllerScope

    public SpringViewControllerScope()

Method Detail

### createConversation

    public Conversation createConversation(ConversationContext context,
                                           String conversationName)

### assertSameScope

    protected void assertSameScope(String beanName,
                                   Conversation conversation)

  Description copied from class: `AbstractSpringOrchestraScope`
  Verify that the specified conversation was created by this scope object.

  Overrides:
    `assertSameScope` in class `AbstractSpringOrchestraScope`
  Parameters:
    `beanName` - is just used when generating an error message on failure.
    `conversation` - is the conversation to validate.

### getConversationNameForBean

    public String getConversationNameForBean(String beanName)

  Find the conversation-controller bean for the current view, then return the conversation that is configured for that controller bean.

  The parameter is completely ignored; the conversation-name returned is that associated with the controller bean, not the specified bean at all.

  Overrides:
    `getConversationNameForBean` in class `AbstractSpringOrchestraScope`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2012 The Apache Software Foundation. All Rights Reserved.