Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Dispatcher eases workflow implementation

Improve your application's workflow with the Dispatcher design pattern and XSL

  • Print
  • Feedback

Page 6 of 7

application.jsp

application.jsp becomes a view controller. Dispatcher tells application.jsp what the next view is:

<jsp:directive.page import="workflow.example.*"/>
<jsp:useBean id="dispatchable" class="workflow.example.Application" scope="Session" />
<jsp:useBean id="controller" class="workflow.example.ApplicationController" scope="Session"/>
<% session.setAttribute("workflowName","application");
   session.setAttribute("factoryName","workflow.example.XMLDispatcherFactory");
   session.setAttribute("workflowScreen","/jsp/application/application.jsp");
%>
<% String nextScreen = (String)session.getAttribute("nextScreen"); %>
<html>
<body>
<bold>My Company's application for employment:</bold>
<form action="/workflowtest/workflow" method=post>
<% if ( nextScreen == null){%>
<jsp:include page="./start.jsp"/>
<%}else{%>
<% pageContext.include(nextScreen); %>
<%}%>
<input type=submit name="operation" value="Next"/>
</form>
</body>
</html>


Next, you'll see some other important JSPs.

demographics.jsp

demographics.jsp, inserted in the middle of application.jsp, collects the demographics information. Notice the pageContext.include(nextScreen) above. Here's the code:

<jsp:useBean id="dispatchable" class="workflow.example.Application" scope="Session" />
<input type=hidden name="current" value="demographics"/>
<table>
<tr>
<td>First name</td><td><input type=text name="firstname" value="<%=dispatchable.first%>"/></input></td>
<td>Last name</td><td><input type=text name="lastname" value="<%=dispatchable.last%>"/></input></td>
<td>Position</td><td><select name="position"/><option value="IT" <%if ( dispatchable.position.equals("IT") ){ %>selected<%}%>>IT</option><option value="HR" <%if ( dispatchable.position.equals("HR") ){ %>selected<%}%>>HR</option></select></td>
</tr>
</table>


felonies.jsp

On the felonies.jsp screen, the candidate reports any felony convictions. Notice I've included an Add button, which contrasts with the way demographics.jsp lets the application.jsp handle the form request:

<jsp:directive.page import="workflow.example.*"/>
<jsp:useBean id="dispatchable" class="workflow.example.Application" scope="Session" />
<input type=hidden name="current" value="felonies"/>
<bold>Please list all the felonies you have committed. If there is more than one hit the add button, when you are finished hit next.</bold>
<table>
<% int i = 0; %>
<% for ( i = 0; i < dispatchable.felonies.size(); i ++ ) { %>
<tr>
<td>what year?</td><td><%=((Felony)dispatchable.felonies.elementAt(i)).yearCommitted%></td>
<td>desciption</td><td><%=((Felony)dispatchable.felonies.elementAt(i)).description%></td>
</tr>
<%}%>
<tr>
<td>Felony year?</td><td><input type=text name="yearCommitted"/></input></td>
<td>Felony desciption</td><td><input type=text name="description" size=50></input></td>
<td><input type="submit" name="operation" value="Add"/></td><td/>
</tr>
</table>


Next, you see the XSL code, which accepts two parameters. It determines the current screen, and, based on that information, it determines the next screen. The fully qualified path of the next screen is output from the XSL, but the code could be changed to output a looked-up alias instead:

  • Print
  • Feedback

Resources