PDA

View Full Version : Is there a way to instantiate object in flow.


garpinc2
Apr 3rd, 2006, 04:49 PM
Is there a way to instantiate object in flow. Basically as part of the flow I want an object to be instantiated for the life of the flow that can then be passed into the actions either in the context or through ognl with pojo actions.

i.e

<flow start-state="Initial">

<instantiate id="theBean" bean="xx.TheBean"/>

<!-- in context -->
<action-state id="Initial">
<action bean="enrollmentSystemRouteCreateUnitOfWorkActivity"/>
<transition on="UnitOfWorkCreated" to="UnitOfWorkCreated"/>
</action-state>

<!-- in arg to pojo action -->
<action-state id="DoNotCommitWork">
<action bean="enrollmentSystemRouteCreateUnitOfWorkActivity"
method="populateObject(#theBean)"/>
<transition on="UnitOfWorkCreated" to="UnitOfWorkCreated"/>
</action-state>

Christian Dupuis
Apr 3rd, 2006, 05:42 PM
Hi garpic2,

have you had the chance to look at the 'var' element. Here is the flow definition from the itemlist example:


<flow start-state="displayItemlist">

<var name="list" type="java.util.ArrayList"/>

<view-state id="displayItemlist" view="itemlist">
<transition on="add" to="createItem"/>
</view-state>

<action-state id="createItem">
<action bean="createItemAction"/>
<transition on="success" to="displayItem"/>
</action-state>

<view-state id="displayItem" view="item">
<transition on="submit" to="addItem"/>
</view-state>

<action-state id="addItem">
<action bean="addItemAction"/>
<transition on="*" to="displayItemlist"/>
</action-state>

</flow>


You can access the var with the name list by using:


Collection list = context.getFlowScope().getRequiredCollection("list");


Cheers
Christian