Announcement Announcement Module
No announcement yet.
import commands-context.xml into application-context.xml Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • import commands-context.xml into application-context.xml

    Hi all,

    does it make sense to import the commands-context.xml into the application-context.xml to get access to the commands / executors via getApplicationContext().getBean("command")?
    Or is it better to define the executor-beans within the application-context.xml?


  • #2
    This can lead to problems. Keep in mind that the commands-context.xml file is "per window". That is, it is processed by the usual Context mechanisms, as well as a custom bean post processor, which automatically sets the ApplicationWindow property of any ApplicationWindowAware class.

    This makes for interesting experiments, especially if you are trying to have a single toggle command to control some non-GUI, non-window specific (i.e. global) function. Unfortunately, since the contexts are created anew and processed independently when you open more than one window, it means that "singleton" in commands-context doesn't actually mean what you'd hope. It is a singleton *IN THAT CONTEXT*, true, but there is more than one context!

    In order to get around this, I ended up creating a ToggleCommand in the main richclient-application-context.xml, and then referred to it in commands-context.xml. Unfortunately, being that the command was created in the main context, the command was never configured properly. i.e. the .label, .image, etc was never set up. This seems to be a weakness that is not easy to correct within the framework, for some reason.

    I ended up creating a class that is specifically used to configure any Commands defined in the main application-context, and passed the command names/ids as a parameter to the custom configurer.

    Messy, but it actually works. If you need help getting this to work in your app, let me know.


    • #3
      Hi rdawes,

      thank's for the hint that the commands-context.xml is used per window. I didn't realize that until now - but it makes definitively sense.
      My application uses just one window, so it wouldn't be a problem. But including the commands-context is not a nice solution.
      I ended up with placing the command-executors into the application-context.xml and defining the actual commands within the commands-context.xml.

      Thanks for your advice,