link to table of contentsgo to previous topicgo to next topiclink to glossaryindex of terms

 

Using the EJB to Display Information

Once the user submits the input page, the reply should contain the account balance, or an error message if the account number was not found, or if another error occurs.› Before you can use the EJB to process the form submission, you need to set up the page to display the results.›

When the servlet receives a POST request from the form, it builds a second HTML page based on what was entered in the InputPage.› To create this response, you need to add an HTML document that contains the text of the response page, and a ServletPost behavior that sends the page when the servlet receives a POST.

To add the balance page:

  1. If your outline is getting cluttered, click InputPage's outline marker to hide its children.
  2. Select MySimpleBank from the outline.
  3. Insert a new HTMLDocument actor.
    Html -> HTMLDocument
  4. Rename HTMLDocument BalancePage.
  5. In the Details pane, set Title to Bank Balances.
  6. In the Comment field, enter: Displays account balance or error message.

To enable POST responses:

  1. Select BalancePage.
  2. Add a ServletGet Behavior from the Palette.
    Saved Group -> ServletGet
  3. Rename the ServletGet behavior ServletPost.
  4. In the Details pane, change the value of Receive: to ServletRequest.doPost.

Now you can add the content of the balance page. The text of the page needs to include the account number the user entered on the first page and the balance of that account.› If the account number was invalid, the page should display an error message. You also need to include text so the user knows what the account number refers to.

To identify the account number:

  1. Select BalancePage from the outline.
  2. Add a new HTMLText actor
    Html -> HTMLText
  3. Rename the HTMLText actor AccountText.
  4. In the Details pane, change the value of Text to Account : .›
    Include a space after the colon for formatting.

Now you need to display the actual account number that the user gave you. The account number gets sent to the servlet as a parameter that you set up earlier on the input page form. Once posted, the capsule holds the value of the accountNumber parameter. Since this value changes each time a different user tries to get their account balance, you need to create a behavior that finds the current value of the parameter and formats it as HTML text.

To display the account number:

  1. Select BalancePage from the outline.
  2. Add an HTMLText actor.
    Html -> HTMLText
  3. Rename the HTMLText actor to AccountNumber.
  4. Add a behavior as a child of AccountNumber.
    Insert -> Action Behavior
  5. Rename the behavior SetAccount.
  6. Edit SetAccount's properties to match the settings below:

SetAccount finds the value of the accountNumber parameter and sends it to the AccountNumber text component.

For formatting the balance page, add a line break between the display of the account number and the balance.

To add a line break:

  1. Select BalancePage.
  2. Add an HTMLLineBreak from the Palette.
    Html -> HTMLLineBreak

So far, the capsule simply redisplays the account number that the user entered on the input page.› You can check this by running the servlet. When you enter an account number and click Get Balance, the browser should show a new page that redisplays the account number.

In the next section you will add the EJB to the capsule, and use it so that it processes the account number and retrieves the balance.



link to table of contentsgo to previous topicgo to next topiclink to glossaryindex of terms © 2003 DigiSlice Corporation