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


Displaying the Results

This lesson shows you how to use the HTMLDoMultiple actor to generate a variable number of output items. It will work with the SqlSelect component to generate a list of the results from the database.

You want to display the results in a bulleted list. The HTML tag that creates bulleted lists is called an unordered list tag, written as <UL>. To generate such a list from the capsule, you need to add an HTMLList actor to the HTML document.

To add an unordered list:

  1. Select BooksPage in the outline.
  2. Add an HTMLList actor from the Palette.
    Html -> HTMLList
  3. Rename HTMLList to ListOfBooks.
    In the Details pane, you can see that by default the list is a bullet list, so you do not need to edit any of its properties.

While you build the capsule, you do not know how many items will be on the shelf, so you do not know how long of a list to make. You need to add an HTMLDoMultiple element as a child of ListOfBooks. This actor generates a variable number of HTML elements that it determines at runtime. As a child of HTMLDoMultiple, you will add an HTMLListItem actor, since this is the element that you want HTMLDoMultiple to generate. Finally, each item on the list will contain text from the database, so you need to add an HTMLText actor to hold the text from the database.

To add a variable number of list Items:

  1. Click on ListOfBooks.
  2. Add an HTMLDoMultiple actor.
    Html -> HTMLDoMultiple
  3. Select HTMLDoMultiple.
  4. Add a list item to DoMultiple
    Insert -> Html -> HTMLListItem
  5. Select the HTMLListItem.
  6. Add HTMLText to the list item.
    Insert -> Html -> HTMLText
  7. Rename HTMLText ListText.

At this point, your capsule should look something like this:

Your query is now in place, as well as the page to display the results. You still need a means to execute the query and write the results to the list.

First, create the action to execute the query. The query needs to execute in order to display the list, so put the action under HTMLDoMultiple.

To add a query behavior to HTMLDoMultiple:

  1. Click on HTMLDoMultiple.
  2. Add an action behavior as a child.
    Insert -> Action Behavior
  3. Name the behavior execute query.
  4. In the Details pane, define it using the following settings:

Now that you have a way to activate and execute the SqlSelect statement, you need to define a way to retrieve the results to the capsule. To do this, add an action group behavior to SqlSelect that activates when a row is retrieved from the result set of the query. By default, an SqlSelect component automatically moves to the next row of the result set when the current row finishes processing, so you do not need to send a "next" message to SqlSelect.

When the statement is executed, it begins at the first row immediately, and automatically moves to each subsequent row when the processing is complete on the current row. By adding an action group behavior that activates on each rowRetrieved event, every action that is included in the group executes each time a row is retrieved.

To set the action group stimulus:

  1. Click on SqlSelect.
  2. Insert -> Action Group Behavior
  3. Rename the behavior to row retrieved.
  4. Set From: to actor.
  5. Set Receive: to Sql.rowRetrieved

Next you need to display the results. You can add two actions to row retrieved to accomplish this. First add an action to print the current row data, then add an action to tell HTMLDoMultiple to go on to its next iteration.

To print the current row's data:

  1. Click on row retrieved in the capsule outline.
  2. Insert -> Action Behavior
  3. Rename the action to set text.
  4. Define set text using the following settings:

To tell HTMLDoMultiple to go to the next item:

  1. Select row retrieved in the outline.
  2. Insert ->Action Behavior
  3. Rename the action print children.
  4. Define the behavior using the following settings:

Save your work and run the servlet!

From the File menu, choose Run. You should see the following screen:

You have just successfully built a servlet that uses an SQLSelect bean and displays a varying number of results in a list. Congratulations!

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