Documentation Archive Developer
Search
Table of Contents Previous Section

Adding a Second Component

In this section, you'll create a new component. Instead of Java, you'll implement its code using WebScript.

  1. In Project Builder's browser, click Web Components in the first column.

  2. Choose File New in Project.

    Note that the Web Components suitcase is selected.

  3. Type GuestList as the name of the new component. Then click OK.

    The WebObjects Component Wizard appears.

  4. Choose None for Available Assistance and WebScript for Component Language.

  5. Click Finish.

  6. In the second column of the browser, click GuestList.wo.

    Note that there is an additional file you didn't have with your Java component. GuestList.wos is your script file, the WebScript equivalent of Main.java in the Main component. For WebScript components, the script files are stored under the component, rather than in the Classes bucket. You'll add code to your script file in a later step.

  7. Double-click GuestList.wo to bring up the component window in WebObjects Builder.

  8. Create a heading for this page, as you did for the Main component. Call it "Guest List" (or something else of your choosing). Then press Enter twice.

  9. Add a WOString below the heading. Then type the text " guests have signed this guestbook."

    You're going to bind this WOString so that it reflects the number of guests who have submitted this form.

  10. In the object browser, click application.

    There is an entry in the second column for the allGuests application variable you created. This entry appears in the Main component as well, since application variables are accessible from anywhere in the code.

    If you click allGuests, you'll see in the third column an entry for count. This is a standard method that returns the number of objects in the array.

  11. Click count and drag to the center rectangle to bind it to the WOString's value attribute.

  12. Save the GuestList component.

    You need to do one more thing so that the GuestList page now displays when the user submits the form.

  13. Go back to Project Builder and view the source code for Main.java. Replace the return statement in the submit method with the following code:
    return application().pageWithName("GuestList");
    

    pageWithName is a standard WebObjects method (defined in the WebApplication class) that allows you to specify a new page to display.

    At this point, the code for Main.java looks like this:

  14. Save Main.java.

  15. Build and run your application.

    Each time you submit the form, the number of guests displayed in the WOString should increase.

    To return to the Main page, you'll have to use your browser's backtrack button. Later in the tutorial, you'll add a hyperlink to return to the Main page.

Table of Contents Next Section