Announcement Announcement Module
No announcement yet.
Using Spring configured Objects in MXML Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using Spring configured Objects in MXML

    What's the best (or recommended way) to use Spring configured objects in an MXML component? For example, if I have some panels that need IoC configured objects such as services and business logic, should I configure those panels in the IoC as well? Or have a way for Panels to get a reference to the ApplicationContext so they can get them via getObject()? It would seem as if the second methodology would add some undesirable coupling. But trying to configure the panels via the IoC seems to come at a cost of losing much of the conveniences offered by MXML of quick coding and a more "visual" coding structure that allows you to easily see component nesting.

    For example, say I have a TabNavigator that loads some panels. Each of those panels need IoC objects (services for example). In MXML using those panels is as easy as:

    <mx:TabNavigator xmlns:mx=""
        <comp:PanelA id="panelA" />
        <comp:PanelB id="panelB" />
        <comp:PanelC id="panelC" />
    Adding another panel is a one line change. But to do this via the IoC, I need to add a property for each new tab, create a setter for it, add the setter to the IoC context configuration, and then add a line of code in the TabNavigator's init sequence to add the new panel as a child. And of course, in turn, each of those panels need to be configured through the IoC rather than simply coded in MXML along with a couple of getObject calls. Going ure IoC seems to be a lot of work when, in this case, the IoC doesn't seem to add any value in terms of being able to inject alternatives during testing, etc. Those benefits seem best geared towards more ActionScript orientated code like services and business logic.

    Some advice and guidance would be appreciated. I've looked at the documentation, but am not finding anything on this subject, namely how to bridge the Spring Objects to MXML markup gap.

  • #2

    for scenarios such as these, we have the Autowired metadata tag that allows you to automatically inject objects from the container into the views.

    See the docs at for more info.



    • #3

      Thank you for the reply and the information. I had seen that section in the documentation, but I misinterpreted the title of it and was thinking it applied to something else. So I ended up skipping over it. Oops. I will read through it now and apply it. If I have any questions, I'll post them.

      Thanks again... both for your assistance and for all the work you and the team do on this framework.