Announcement Announcement Module
Collapse
No announcement yet.
How to access beans created in command-context.xml Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to access beans created in command-context.xml

    I'm trying to configure toolbar commands (see this thread http://forum.springframework.org/showthread.php?t=17521) and I'm running into a dead end.

    How can I access the beans defined in command-context.xml? I assumed that they would be available using the basic idiom:

    Code:
            CommandGroup group = (CommandGroup)Application.services().getBean("switchToViewCommandGroup");
    However, that results in this exception:

    Code:
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'switchToViewCommandGroup' is defined: org.springframework.beans.factory.support.DefaultListableBeanFactory 
    defining beans [application,lifecycleAdvisor,applicationDescriptor,applicationObjectConfigurer,applicationEventMulticaster,componentFactory,
    binderSelectionStrategy,lookAndFeelConfigurer,messageSource,imageResourcesFactory,imageSource,iconSource,
    formComponentInterceptorFactory,rulesSource,formPropertyFaceDescriptorSource,PhysicianTableView,OfficeLocationView,pdb]; root of BeanFactory hierarchy
    I am defining the command like this:

    Code:
    	<bean id="switchToPhysicianViewCommand"
    	      class="com.fhm.pdbm.ui.command.SwitchToViewCommand">
            <property name="viewDescriptor">
                <ref bean="PhysicianTableView" />
            </property>
        </bean>
        <bean id="switchToOfficeLocationViewCommand"
              class="com.fhm.pdbm.ui.command.SwitchToViewCommand">
            <property name="viewDescriptor">
                <ref bean="OfficeLocationView" />
            </property>
        </bean> 
    
    	<bean id="switchToViewCommandGroup"
    		class="org.springframework.richclient.command.CommandGroup"
    		factory-method="createExclusiveCommandGroup">
    		<constructor-arg>
    			<list>
    				<ref bean="switchToPhysicianViewCommand"/>
    				<ref bean="switchToOfficeLocationViewCommand"/>
    			</list>
    		</constructor-arg>
    	</bean>
    So, how do I access the beans in this file? I can't quite decipher the code that initializes the menus and toolbar - it's very complicated. :shock:

    Thanks,
    Larry.
    Last edited by robyn; May 14th, 2006, 08:40 PM.

  • #2
    Ok, I found this one. You access the special bean factory from LifecycleAdvisor#getCommandBarFactory().

    From there you can use the normal getBean() call, like this:

    Code:
            CommandGroup group = &#40;CommandGroup&#41;getCommandBarFactory&#40;&#41;.getBean&#40;"switchToViewCommandGroup"&#41;;
    HTH.
    Larry.

    Comment

    Working...
    X