views:

394

answers:

4

Hi,

I got pretty big webflow definition, which I do not want to copy/paste for reusing. There are references to action bean in XML, which is kind natural.

I want to use same flow definiton twice: second time with actions configured differently (inject different implementation of service to it).

Is there easy way to do this?

A: 

I don't think you can use the same webflow definition with the actions configured in two different ways.

If you want to use different actions you'll either have to reconfigure your action beans then redeploy your app or create a separate webflow definition with the differently configured beans.

This is a great Spring WebFlow resource.

Owen
A: 

Problem is I want to use same flow with different beans at once, in the same app. Copy/Paste is bad, but I dont see other solution for now :-(

+1  A: 

You could try creating a new flow that extends the "pretty big one" and adding flowExecutionListeners to it.

The interface "FlowExecutionListener"defines methods for the following events in flow execution:

  • requestSubmitted
  • requestProceessed
  • sessionCreating
  • sessionStarting
  • sessionStarted
  • eventSignaled
  • transitionExecuting
  • stateEntering
  • viewRendered
  • viewRendering
  • stateEntered
  • paused
  • resuming
  • sessionEnding
  • sessionEnded
  • exceptionThrown

You can write a handler that injects the required resources to your flow (and use different handles with different flows) by storing it in the RequestContext, where you can access it in your flow definition.

Note that in that case you would still have to modify the "pretty big flow" to use those resources instead of referencing the beans directly.

Arnelism
the question is now if action beans are statefull or stateless :-) have to check
A: 

I'm in the same fix that you're in...i have different subclasses which have corresponding action beans, but a lot of the flow is the same. In the past we have just copied and pasted...not happy with that! I have some ideas I am going to try out with using the expression language. First, I came up with an action bean factory that will return the right action bean to use for a given class, then i can call that factory to set a variable that i can use instead of the hard-coded bean name.

Here's part of the flow:

<action-state id="checkForParams">
    <on-entry>
        <set name="flowScope.clientKey" value="requestParameters.clientKey"/>
        <set name="flowScope.viewReportBean" 
                 value="reportActionFactory.getViewBean(reportUnit)"/>
    </on-entry>
    <evaluate expression="viewReportBean"/>

The evaluate in the last line would normally refer directly to a bean, but now it refers to the result of the "set" I just did.

Good news--the right bean gets called.

Bad news--anything in the flow scope needs to be Serializable, so I get a NotSerializableException--arggh!

I can try setting something on a very short-lived scope, in which case it will need to get called all the time...or I can figure out some kind of proxy which holds the real bean as a proxy declared "transient".

BTW, I am using Spring 2.5.6 and webflow 2.0.7. Later versions may have better ways of handling this; in particular, EL's have gotten some attention, it seems. I'm still stuck with OGNL, which is the Spring 1.x EL.

I'm sure some webflow guru knows other ways of doing things in a less clunky fashion...

bobtins