Modules in a Struts process

A Struts process can be divided into several modules. For example, in a credit card application process, you can have a main module to take care of the whole application process and a sub-module to collect credit card owner information. After the sub-module finishes collecting card owner information, the main module submits the information for processing

The tookit Struts Extensions component enables you to define modules and sub-modules for your Struts process. Each module has its own Struts configuration file. The different struts-config files are specified as parameters to the Struts ActionServlet or its subclass in the web.xml file of your application EAR file. To preserve session management, you can only switch to modules in the same EAR file. The Session Manager manages data sharing and access.

When switching from one module to another, you need to do the following:
  1. In main module Struts configuration file, define mapping from the CHA context associated with the preceding module to the CHA context associated with the succeeding module.
  2. In JSP files, prefix the request action URI with the succeeding module.
  3. In the sub-module Struts configuration file, define a final state as the exit criteria of the sub-module.
Here's an example of the main module Struts configuration showing the configuration of switching to another module:
<action path="/creditCardWellcome" forward="/creditCardsWellcome.jsp"/>
	<action name="creditCardForm" path="/apply" 
	className="com.ibm.btt.struts.config.BTTSwitchActionMapping" 
	type="org.apache.struts.actions.SwitchAction" processCtxMapperTo="mapper1" 
	processCtxMapperFrom="mapper2" input="/creditCardsWellcome.jsp" 	validator="com.ibm.btt.samples.html.ApplyXVal">
	<forward name="success" contextRelative="true" path="/financialInfo/requestDataPage.jsp "/>
	<forward name="creditCardsPage" path="/creditCardsPage.jsp"/>
</action>
<processctxmappers>
	<processctxmapper id="mapper1">
		<ctxmaps from="firstName" to="firstName"/>
		<ctxmaps from="middleName" to="middleName"/>
		<ctxmaps from="lastName" to="lastName"/>
		<ctxmaps from="income" to="income"/>
		<ctxmaps from="security" to="security"/>
		<ctxmaps from="social" to="social"/>
		<ctxmaps from="number" to="number"/>
	</processctxmapper>
	<processctxmapper id="mapper2">
		<ctxmaps from="firstName" to="firstName"/>
		<ctxmaps from="middleName" to="middleName"/>
		<ctxmaps from="lastName" to="lastName"/>
		<ctxmaps from="income" to="income"/>
		<ctxmaps from="security" to="security"/>
		<ctxmaps from="social" to="social"/>
		<ctxmaps from="number" to="number"/>
	</processctxmapper>
</processctxmappers>
<flowcontext contextName="creditCardCtx" local="true"/>
Here is the JSP file that implements the module switching:
<btt:form
	action="/apply.do?prefix=/btt/html/creditCard/financialInfo&page=/finacialInfo.do">	<center>
	<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH="75%"><TR><TD>
			<CENTER><btt:errors /></CENTER>
		</TD></TR><TR><TD>
			<input type="radio" name="userType" value="new" checked="checked">
		  <btt:label	text="I_do_not_have_an_account" />
		</TD></TR><TR><TD>
		</TD><TR><TD><BR>
			<btt:radio property="userType" value="existing" />
			<btt:label text="I_have_an_account" /> <btt:text property="accountNumber" />
		</TD></TR><TR><TD ALIGN="center">
			<INPUT TYPE="submit" VALUE=<btt:label text="Continue"/>>
	</TABLE>
	</center>
</btt:form>
Here's the sub-module Struts configuration:
<action name="financialInfoForm" path="/finacialInfo" 
	className="com.ibm.btt.struts.config.BTTEJBActionMapping" 
	type="com.ibm.btt.struts.actions.EJBAction" 
	input="/requestDataPage.jsp" invokerId="financialinfoinvoker">
	<forward name="success" path="/requestDataPage.jsp"/>
</action>
<action name="financialInfoForm" path="/finacialFinal" 
	className="com.ibm.btt.struts.config.BTTEJBActionMapping" 
	type="com.ibm.btt.struts.actions.EJBAction" 
	input="/requestDataPage.jsp" invokerId="financialfinalinvoker" 
	validator="com.ibm.btt.samples.html.FinancialInfoXVal">
	<forward name="creditCardsPage" path="/creditCardsPage.jsp"/>
	<forward name="cancel" path="/cancelConfirmation.jsp"/>
</action>
<finals>
	<final type="forward" name="/creditCardsPage.jsp"/></finals>
The financialInfo action then calls the financialinfoinvoker invoker to invoke a business process or Single Action EJB through the EJB Access Action to do the transaction.

As defined in the <final> tag, when any action in the sub-module has an ActionForward to the creditCardsPage.jsp page, the Struts process exits from the sub-module.