Announcement Announcement Module
No announcement yet.
adding to a pre-defined list Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • adding to a pre-defined list

    I have defined a hierarchy of menu data items in menu.xml which eventually gets turned into a JMenu structure. The menu is generally static (meaning unchanging) however I need to support the ability to plug-in a menu into the hierarchy from a separate bean.xml file

    example: Assume this list is defined in menu.xml

     <bean id="Main.Menu.List" class="org.springframework.beans.factory.config.ListFactoryBean">
         <property name="sourceList">
              <ref local="MenuA"/>
              <ref local="MenuB"/>
              <ref local="MenuC"/>
    <bean id="MenuA" class="menu.MenuData" init-method="init">
         <constructor-arg value="Menu A"/>
    <bean id="MenuB" class="menu.MenuData" init-method="init">
         <constructor-arg value="Menu B"/>
    <bean id="MenuC" class="menu.MenuData" init-method="init">
         <constructor-arg value="Menu C"/>
    I then would have another menu.xml file in another jar (say it is called PlugIN.jar). I add a URL for each instance of menu.xml found in the classpath to my ApplicationContext so the we load all of the menu.xml bean definition files in the same context.

    The menu.xml in the PluginJar might be like this :

    <bean id="MenuD" class="menu.MenuData" init-method="init">
         <constructor-arg value="Menu D"/>
    How do I add this MenuD to the Main.Menu.List
    But what I can't figure out is how to go about adding this MenuD to the "Main.Menu.List" bean. I looked into the parent/child approach but I don't think that will work as what I want is to mutate (add) to an existing list bean and not define a new bean in terms of another.

    I was thinking of an approach where I make the plugin menu objects different than regular menus and then creating a post processor that will scan the menu beans looking for special plugin beans. When it finds one the new plugin menu bean would have to have the name of a parent menu bean
    and the post processor would then stitch them together.

    I am hoping there is a more simple way to do this.

    I am still very new to Spring so I am sure I am overlooking a very simple solution but at the moment I cannot see it.

    Thanks in advance