Go to page:
Prev 1 2 3 4 5 6 7 8 9 10 11 12 13 Next
Developing the Custom User Interface
After we have successfully modified the BPEL code we are ready to develop the custom user interface through which the user will approve the airline tickets. We will develop three JSPs:
- One to display the tasks waiting for approval
- One to display and enter the airline ticket information
- One to make the ticket confirmation
(continued)To simplify the data management we will use the XML façade for the TravelResponse message. For this we use the schemac tool on the Airline WSDL. Let us now develop the first JSP.
Displaying Tasks
To display the tasks that are waiting for approval, we use the BPEL Server Locator through which we connect to the BPEL default domain. Next we connect to the Worklist service and get the list of tasks that require approval:
<%@page import="java.util.Date" %>
<%@page import="com.oracle.bpel.client.Locator" %>
<%@page import="com.oracle.services.bpel.task.IWorklistService" %>
<%@page import="com.oracle.services.bpel.task.ITask" %>
<%
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
Locator locator = new Locator("default", "bpel");
IWorklistService worklist =
(IWorklistService)locator.lookupService(IWorklistService.SERVICE_NAME);
ITask[] tasks = worklist.listTasksByAssignee("travel@packtpub.com");
%>
...
Next we list the tasks in the table and make a hyperlink to the next JSP through which we display the ticket information. Note that we use the task ID to identify which task the user has selected:
...
<html>
<head>
<meta http-equiv="PRAGMA" content="NO-CACHE" />
<meta http-equiv="EXPIRES" content="-1" />
</head>
<body>
<h1>BPEL Travel process tasks waiting for approval</h1>
<table>
<%
for ( int i = 0; i < tasks.length; i ++ )
{
ITask thisTask = tasks[i];
if ( ! "TravelUserTask".equals( thisTask.getCreator() ) )
{
continue;
}
String title = thisTask.getTitle();
String taskId = thisTask.getTaskId();
Date expiration = null;
if( thisTask.getExpirationDate() != null )
expiration = thisTask.getExpirationDate().getTime();
%>
<tr>
<td>
<%= expiration %>
</td>
<td>
<a href="displayTicket.jsp?taskId=<%= taskId %>"><%= title %></a>
</td>
</tr>
<%
}
%>
</table>
</body>
</html>
Displaying and Entering Ticket Information
In the second JSP we display information about the airline ticket and allow the user to edit the approval field (which can be true or false). We again use the Locator to connect to the BPEL domain. Then we connect to the Worklist service and locate the task by ID. We use the XML façade to obtain the ticket data:
<%@ page import="java.util.*" %>
<%@ page import="org.w3c.dom.Element" %>
<%@ page import="com.oracle.bpel.client.Locator" %>
<%@ page import="com.oracle.services.bpel.task.IWorklistService" %>
<%@ page import="com.oracle.services.bpel.task.ITask" %>
<%@ page import="com.packtpub.service.airline.FlightConfirmationType" %>
<%@ page import="com.packtpub.service.airline.FlightConfirmationTypeFactory"
%>
<html>
<head>
<meta http-equiv="PRAGMA" content="NO-CACHE" />
<meta http-equiv="EXPIRES" content="-1" />
</head>
<body>
<%
String taskId = request.getParameter( "taskId" );
if( taskId == null || "".equals( taskId ) )
{
%>
<a href="displayTasks.jsp">
List of BPEL Travel process tasks to approve.</a>
<%
}
else
{
Locator locator = new Locator( "default", "bpel" );
IWorklistService worklist =
(IWorklistService)locator.lookupService(
IWorklistService.SERVICE_NAME );
ITask task = worklist.lookupTask( taskId );
Element rsElement = (Element) task.getAttachment();
FlightConfirmationType fc =
FlightConfirmationTypeFactory.createFacade(rsElement);
String flightNo = fc.getFlightNo();
String travelClass = fc.getTravelClass();
float price = fc.getPrice();
boolean approved = fc.getApproved();
%>
...
We display the ticket data in a form and allow the user to edit the approved field. The form is linked to the third JSP:
...
<h1>Travel Ticket Approval User Task</h1>
<form action="confirmTicket.jsp" method="POST">
<!-- The task ID is passed from page to page -->
<input type="hidden" name="taskId" value="<%=taskId%>" />
<table>
<tr>
<td>Flight number</td>
<td><%= flightNo %></td>
</tr>
<tr>
<td>Travel class</td>
<td><%= travelClass %></td>
</tr>
<tr>
<td>Price</td>
<td><%= price %></td>
</tr>
<tr>
<td>Approved</td>
<td>
<input type="text" name="approved" value="<%= approved %>"/>
</td>
</tr>
</table>
<input type="submit" alt="Confirm Ticket" value="Confirm Ticket"/>
</form>
<%
}
%>
</body>