In this step you will create the data processing elements of your page flow. The data processing of your page flow consists of three parts: (1) accepting user requests for a credit report, (2) the retrieval of credit reports from a web service, and (3) the storage of the credit reports within the page flow.
(1) The first task is accomplished through a Form Bean. Form Beans act as intermediaries between the requests that users enter into JSP pages and your page flow. The data that users submit is typically stored in a Form Bean, which is then passed to an Action method for further processing.
(2) The second task is accomplished through an Action method which requests and retrieves credit reports from a web service.
(3) The third task is accomplished through a member variable.
Member variables are Java objects that you place on your page flow, typically
to store some data content. In this case you will store the credit reports
retrieved from the web service, so that they can be displayed to the user.
The tasks in this step are:
To Generate a WSDL File and a Web Service Control
In this step you will create a control for the InvestigateSync web service, which allows your page flow to request and receive credit-worthiness reports from the web service.
In this task you connect the page flow and the web service through the web service control you created in the previous task.

To Add an Action Method and a Form Bean
In this task you will add an Action method that processes user requests for credit reports. This Action method receives user input, retrieves a credit report from the InvestigateSync web service, and then forwards the user to a JSP page where the credit report is displayed.
You will also add a Form Bean. Form Beans are used to separate the data presentation layer from the data processing layer of your web application. Form Beans are used as intermediaries between the data that users input into JSP pages and the Action methods. Instead of submitting the data directly to the Action method, the data is first databound to a Form Bean and this Form Bean is then passed as a parameter to the Action method. This helps to separate the presentation layer (i.e., the user input forms on the JSP pages) and the processing layer (i.e., the Action methods), because the Form Bean can play a flexible, intermediary role.
In this task you will add a taxID field to the Form Bean. This field will carry the data that users input into the JSP page (a page not yet created).
Before you move on to the next task, click the Source View tab, to see the code that has been generated. You have just added one Action method and one Form Bean shown below.
Notice that the Action method pollForCreditReport
takes the Form Bean parameter PollForCreditReportForm
form. Also notice that the Form Bean takes the form of an ordinary
Java class with fields, and setter and getter methods on those fields.
In this task you will add code to the pollForCreditReport Action method. The code you add has two purposes: (1) it polls the web service for a credit report and (2) it controls user navigation.
Polling is a form of synchronous communication between a client and a web service. When a client polls a web service it first asks the web service to begin some process. The client then waits some predetermined amount of time after which it asks the web service if the process is complete. If the process is complete then the client retrieves the result of the process; if the process is not complete, then the client continues to wait for the process to be completed.
/**
* @jpf:action
* @jpf:forward name="response" path="response.jsp"
*/
protected Forward pollForCreditReport(PollForCreditReportForm form)
throws java.lang.InterruptedException
{
/**
* Request a credit report from the InvestigateSync
* web service.
*/
investigateSyncControl.requestCreditReport(form.taxID);
/**
* Poll the isReportReady method 20 times, once a second,
* to check if the result is ready.
*/
for(int i=0; i<20; i++)
{
/*
* If the report is ready, get the credit report,
* store it in m_applicant, and forward the user to
* response.jsp.
*/
if(investigateSyncControl.isReportReady() == true)
{
m_applicant = investigateSyncControl.getCreditReport();
return new Forward("response");
}
else
{
/*
* If the report is not ready, wait one second before
* polling again.
*/
try
{
Thread.sleep(1000,0);
}
catch (java.lang.InterruptedException e)
{
}
}
}
/*
* The credit report was not delivered in the time allowed.
* Store a message in the applicant object and Forward the user
* to the response.jsp page.
*/
m_applicant.message = "The Investigate Web Service did not respond it the time allowed.";
return new Forward("response");
}
/**
* The m_applicant object stores the credit report provided
* by the InvestigateSync web service.
* The tag on response.jsp is data bound to m_applicant.
*/
public InvestigateSyncControl.Applicant m_applicant;
Re-arrange the Flow View Icons
This task does not change the functionality of your page flow, but it does make it easier to understand how the different parts of the page flow are related to one another.

Related Topics
Using Form Beans to Encapsulate Data
Using Polling as an Alternative to Callbacks
Tutorial: Web Services, Step 3: Add Support for Synchronous Communication
Click the arrow to navigate to the next step in the tutorial.