Step 3: Processing Data

In this step you will learn how to process data submitted from users and forward users to a page where the results are displayed. The tasks in this step are:


Edit the hello Method to Construct a Message

First you will edit the hello action method to implement the business logic for handling the user input. Specifically, you will construct a String message that takes the name from the form bean and you will make this message available to the next page. The message is made available to the next page by making it an attribute (property) of the request object, which can be read by the next JSP page.

  1. Make sure that HelloController.jfp is displayed in Flow View in the main area.
  2. In Flow View, double-click the hello icon to see the source code for this action.

  3. In Source View, edit the hello method so it appears as follows. The added code is shown below in red:
        /**
         * @jpf:action
         */
        protected Forward hello(HelloForm form)
        {
            // Construct a message from the submitted name.
            String message = "Hello, " + form.getName() + "!";        
            
            // Place the message on the request object.
            getRequest().setAttribute("message", message); 
            
            return new Forward("success");
        }
  4. Press Ctrl+S to save your work.

Edit the hello Method to Forward the User

Now you will enhance the hello method to implement the navigation logic. Specifically, you will modify the action method to call the response.jsp page.

  1. In Source View, place the cursor somewhere within the signature of the hello method.

  2. In the Property Editor, click the plus sign to the right of the section labeled forward List.

  3. In the Property Editor, click the plus sign to the left of forward(1).

  4. In the Property Editor in the section below forward(1), in the name property, enter success, and press the Enter key.

  5. In the Property Editor in the section below forward(1), in the path property, enter response.jsp, and press the Enter key.

  6. Press Ctrl+S to save your work.

The hello method is now complete and should like this in Source View.

Rearrange the Icons in Flow View

Let's rearrange the icons in Flow View so that it becomes easier to read the flow.

  1. Click the Flow View tab.
  2. Rearrange the icons so that they appear as follows.



    Notice that the response.jsp icon is grey out. This indicates that the JSP page response.jsp is referred to in the Controller file, but does not yet exist in the Page Flow folder.
  3. Press Ctrl+S to save your work.

Test the Web Application

Let's now test the page flow to make sure you have correctly executed the above steps.

  1. Make sure that the HelloController.jfp file is displayed in the main area.
  2. Click the Start button, shown below:

  3. When the Workshop Test Browser launches, in the Name field, enter [your_name] and click hello.



    The following error is displayed in the Workshop Test Browser.



    The reason an error is displayed is because the hello method forwards the user to the response.jsp page but that does not yet exist. You will correct this situation in the next step.

Click one of the following arrows to navigate through the tutorial: