Results 1 to 5 of 5

Thread: How to paramaterise action in the webflow.xml?

  1. #1
    Join Date
    Aug 2004
    Posts
    1,905

    Default How to paramaterise action in the webflow.xml?

    Hi all,

    A couple of questions. I have an action ActionA which locks a series of objects. I want to pass in a strategy which determines the objects to lock.

    There are a couple of implementations, used in different flows. I don't really want to have one bean in context.xml per strategy implementation, what I want is to effectively autowire in the flow.xml, i.e.:

    context.xml
    <bean id="lockAction"/> <!-- the action that locks the objects -->
    <bean id="individualObject"/> <!-- an implementation provide the objects -->
    <bean id="objectAndChildren"/> <!-- an implementation provide the objects -->

    and then in flow do something like:

    flow.xml
    <action name="lockAction">
    <property name="objectRetrievalStrategy">
    <ref bean="objectAndChildren"/>
    </property>
    </action>

    in another flow:
    <action name="lockAction">
    <property name="objectRetrievalStrategy">
    <ref bean="individualObject"/>
    </property>
    </action>

    If I cannot do this, then I suppose I could chain the two actions, and have the strategy populate the event or context that the lockAction then uses.

    If I chose this second approach, what would be the best approach in returning information from one event to another in the following scenarios:

    a: actionA is followed immediately by actionB
    b: actionA is followed by actionB which is followed by actionC, and actionC needs information produced by actionA.

    Should I populate the event, or the request context?

    Many thanks.

    Colin

  2. #2
    Join Date
    Aug 2004
    Posts
    1,905

    Default Not very nice, but functional

    OK, so I have resorted to making the action implement ApplicationContextAware.

    At "flow" time the action is parameterised with the name of the bean it wants, i.e.:

    <action name="lockAction">
    <property name="individualObject"/>
    </action>

    During the action's execute method, I retrieve the bean from the application context.

    Bit nasty, but how else can I do it?

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

    Default

    Give the new type conversion machinery a try... it might actually work quite nicely.

    Specifically, create you a custom Converter -- like "TextToBean" and give it an alias when registered with the conversion service, like "bean" for example. Then in your xml say:

    <property name="objectAndStrategy" type="bean"/>

    ... that should pass the objectAndStrategy string to the converter for conversion, at which you could lookup the bean in the AC and return it. That way your action props end up being nicely typed strategies, not bean ids.

    Good luck.

    Keith
    Keith Donald
    Core Spring Development Team

  4. #4
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Excellent. Will give it a try.

    Thanks.

  5. #5
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Haven't tried your ObjectType property editor yet, but could you not add another element into the "property" element called "ref" which does exactly this?

    Many thanks,

    Col

Similar Threads

  1. Exit action from view state
    By pglezen in forum Web Flow
    Replies: 5
    Last Post: Oct 7th, 2005, 02:23 PM
  2. autowire for struts action
    By houyunf in forum Web
    Replies: 2
    Last Post: Sep 2nd, 2005, 12:33 PM
  3. Replies: 4
    Last Post: Aug 1st, 2005, 03:45 PM
  4. Some questions about JMX support
    By ussr_redarmy in forum Container
    Replies: 5
    Last Post: Jul 7th, 2005, 08:20 PM
  5. Question about Action
    By snpe in forum Swing
    Replies: 3
    Last Post: Nov 8th, 2004, 08:58 AM

Posting Permissions

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