Results 1 to 7 of 7

Thread: FormAction does not implement ApplicationContextAware?

  1. #1
    Join Date
    Jun 2005
    Location
    New York, NY
    Posts
    5

    Default FormAction does not implement ApplicationContextAware?

    Or am I missing something? It seems perfectly acceptable (and even preferable) for FormAction to implement ApplicationContextAware, yet it does not. Why?

    Josh

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    Why does it need to?
    Keith Donald
    Core Spring Development Team

  3. #3
    Join Date
    Jun 2005
    Location
    New York, NY
    Posts
    5

    Default

    Why does Spring's AbstractController need to? It doesn't, but it's awfully convenient that it does. With that said, the question I should have asked was why doesn't either the Action interface or AbstractAction extend/implement the ApplicationContextAware interface?

    In my apps, the main responsibility of the controller layer is to look up business delegates from the spring context, executing whatever method, and then dispatching to a view with the output. Using webflow, everytime I create a new controller, I have to explicitly tell that controller to make itself aware of its own context? Seems like unnecessary boiler-plate code to me...

    Maybe I'm missing something? Is it a question of decoupling spring webflow from spring core?

  4. #4
    Join Date
    Jun 2005
    Location
    New York, NY
    Posts
    5

    Default

    Allow me to correct myself again... In addition to being ApplicationContextAware, AbstractAction should also implement the getApplicationContext() method. This would make AbstractAction behave more like AbstractController, which I would argue is a good thing...especially for people like me who are refactoring Spring Controllers into Spring Web Flow Actions.

  5. #5
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    But why not just use dependency injection everywhere?

    Basically, we've taken the stance to date that use of the AC from a webflow action is not a common case and doesn't warrant providing a reference to it in AbstractAction. If you need the AC, you could always create your own action superclass that was AC aware.

    What kinds of things do you need it for and why can't you just use DI?

    Keith
    Keith Donald
    Core Spring Development Team

  6. #6
    Join Date
    Jun 2005
    Location
    New York, NY
    Posts
    5

    Default

    Dependency Injection... Oh yes, I remember hearing something about that strange little concept. Sometimes the obvious escapes me. For business delegates, DI definitely makes the most sense. But in the case where the controller needs one or more (determined at runtime) prototype bean instances from the bean factory, access to the context is necessary.

    I guess the case could be made that controllers should be dumb proxies, not responsible for implementing logic which requires the instantiation of multiple prototype beans... Nonetheless, there are those times when convenient access to the context from the controller is useful, IMHO.

    Perhaps the most compelling argument for making AbstractAction classes ApplicationContextAware, is that AbstractAction classes are. Simply having the get/setApplicationContext() interfaces available to FormActions makes the process of adapating from Spring MVC to WebFlow more natural, and existing code slightly more portable.

    From a design perspective, I understand your rationale. From a API consumer perspective, I would find it useful.

    As a sidenote, I enjoy using the framework and it's been fun learning it. Nice work.

    Josh

  7. #7
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    Not neccessarily, you can use lookup-method or inject a custom locator to return a prototype :-)

    Glad u like! SWF will only get better :-)

    Keith
    Keith Donald
    Core Spring Development Team

Similar Threads

  1. How to implement a custom BeanFactory?
    By ttlaitin in forum Architecture
    Replies: 4
    Last Post: Feb 10th, 2010, 11:24 AM
  2. Add to errors in FormAction
    By garethmorgan in forum Web Flow
    Replies: 5
    Last Post: Jul 21st, 2005, 09:23 AM
  3. FormAction or Validator for this situation?
    By tortuga in forum Web Flow
    Replies: 3
    Last Post: Jul 20th, 2005, 05:19 AM
  4. Replies: 3
    Last Post: Jul 5th, 2005, 05:33 AM
  5. Replies: 2
    Last Post: Nov 22nd, 2004, 04:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •