Cmobilecom AF 5.19 Developer Guide

10 Flow

A flow consists of a number of steps to complete one or more related tasks. There are 3 types of flows supported:

Step Interface Implementation

Create a number of steps and add them into a step flow. Then start the step flow. For example,

public class StepOne implements Step {
	private StepFlow stepFlow;

	public StepOne(StepFlow stepFlow) {
		this.stepFlow = stepFlow;
	}

	@Override
	public boolean shouldSkip() throws SystemException {
		return false;
	}
	
	@Override
	public void run() throws SystemException {
		...
		
		stepFlow.stepCompleted(this);
	}
}

public class StepTwo implements Step {
	private StepFlow stepFlow;

	public StepTwo(StepFlow stepFlow) {
		this.stepFlow = stepFlow;
	}

	@Override
	public boolean shouldSkip() throws SystemException {
		return false;
	}
	
	@Override
	public void run() throws SystemException {
		...
		
		stepFlow.stepCompleted(this);
	}
}

StepFlow stepFlow = new StepFlow();
stepFlow.addStep(new StepOne(stepFlow));
stepFlow.addStep(new StepTwo(stepFlow));
stepFlow.start();

Bean Flow with Form Designs

An EntityBackingBean can navigate through a number of steps with different form designs to complete one or more tasks. Each step needs to define a Next navigation except the last step. "Back" navigations (direction="back"), if not defined, will be dynamically created during a bean flow. For example, shopping cart checkout flow:

Step 1: Shopping Cart


<viewConfig>
	<viewType>ENTITY</viewType>
	<propertiesToShow>orderItems</propertiesToShow>

	...
	
	<beanFlowNavigation direction="next">
		<formDesign>
			<entityType>Sales.SO</entityType>
			<formId>1011-2</formId>
		</formDesign>
		<command visibleName="CheckOut" nameLocalized="false" />
	</beanFlowNavigation>	

</viewConfig>
The next step will be using the form design 1011-2. The next command display name is CheckOut. Default is Continue.

Step 2: Shipping and Billing Addresses


<viewConfig>
	<viewType>ENTITY</viewType>
	<propertiesToShow>shippingMethod,shipTo,billTo</propertiesToShow>
	
	...
	
	<beanFlowNavigation direction="next">
		<formDesign>
			<entityType>Sales.SO</entityType>
			<formId>1011-3</formId>
		</formDesign>
	</beanFlowNavigation>	
	
</viewConfig>
The next step will be using the form design 1011-3.

Step 3: Payment Information


<viewConfig>
	<viewType>ENTITY</viewType>
	<propertiesToShow>payment</propertiesToShow>
	
	...
		
	<beanFlowNavigation direction="next">
		<formDesign>
			<entityType>Sales.SO</entityType>
			<formId>1011-4</formId>
		</formDesign>		
	</beanFlowNavigation>

</viewConfig>
The next step will be using the form design 1011-4.

Step 4: Confirmation


<viewConfig>
	<viewType>ENTITY</viewType>
	<propertiesToShow>store,customer,orderItems,totalBeforeTax,tax,total,shippingMethod,shipTo,billTo,payment</propertiesToShow>
	<readOnly>true</readOnly>
	
	<!-- calculate total price before showing confirm page -->
	<param name="order.preCalcPrice" value="true"/>
	<param name="order.preCalcPrice.ignoreError" value="false"/>
	
	...
	
	<beanFlowNavigation direction="next">
		<formDesign>
			<entityType>Sales.SO</entityType>
			<!-- show completed order -->
			<formId>1010</formId>
		</formDesign>		
		<command exec="Pay" visibleName="CompleteOrder" nameLocalized="false" />
	</beanFlowNavigation>

</viewConfig>
This step is a confirmation step showing all information entered in previous steps and order total price is calculated before shown.

The next step will be using the form design 1010. The Next command display name is Complete Order. Before going to the next step, the action Pay will be executed, which will make payment. The payment may need to be redirected to a payment gateway for approval. After the payment is completed, the bean flow will navigate to its final step with form design 1010. The final step is not in a bean flow, so it can not go back to any previous step.

The exec attribute specifies a list of actions to take before navigation. The actions must be implemented in the EntityBackingBean as following. For example,


	@Override
	protected void execBeanFlowNavigationCommand(String command, Direction direction) throws SystemException {
		if (direction.equals(WebFlowNavigation.Direction.NEXT)) {
			if (command.equals("Pay")) {
				// pay the order
			}
		}
	}

Page Flow

A page can navigate to another page by redirect after a command is completed or when a certain condition occurs, for example, when an embedded entity is not found.

See Bookmarkable URL - Redirect, and Redirect If Entity Not Found.

User Defined Entity PropertiesAuthenticationFrames / No Frames