Create a second component
When users click the Show All Registrants button, the Registration application displays a second page containing the list of registrants. You'll now create the second page of the application.
- In the Registration application window, click the plus sign to add a new component.
- Type Registrants as the name of the component and press Enter.
A new component window is displayed.
Create the component's interface
The Registrants component uses a repetition to display the information in the list of registrants.
- Drag a WORepetition element from the Abstract Elements palette to the Registrants component window.
- Drag three WOStrings from the Abstract Elements palette into the WORepetition.
Create variables
Now Registrants needs a variable that will contain the list the WORepetition is to display.
- Create a variable in the Registrants component, name it myNameList, and make it an array of type aPerson.
Bind elements to the script
- Bind myNameList to the repetition's list attribute.
- Bind the three WOStrings to the three attributes in aPerson as shown below:
WebObjects Builder creates a variable named aPerson and binds to the repetition's item attribute. aPerson is an aPerson dictionary.
Implement Registrants
- Open the Script window, and change the Registrants implementation to look like this:
- You're done implementing Registrants, so save and close the component. Choose File Save All to make sure that the entire application is saved.
import next.util.*; import next.wo.*; public class Registrants extends Component { ImmutableHashtable aPerson; ImmutableVector myNameList; public void awake() { myNameList = ((Application) application()).manager().registrants(); } public void setAPerson(ImmutableHashtable newPerson) { aPerson = newPerson; } }
In the awake method, Registrants accesses the list of all registered people through the Application object's manager instance variable and assigns it to the myNameList instance variable. This is done in awake so that Registrants retrieves the list before the page is displayed.
setAPerson is invoked when the WORepetition iterates through myNameList. It assigns the aPerson variable to the method's argument.
Note: Be sure to change the declarations of myNameList and aPerson as shown above.
Add Registrants.wo to the project
As a final step before compiling, you need to add Registrants.wo to the project in Project Builder. Project Builder must know about Registrants.wo so that the file Registrants.java is compiled during the build. If you had written Registrants.wo in WebScript, it wouldn't be necessary to add the component to the file because WebScript files are not needed during the build cycle.
- Double-click the word Interfaces in Project Builder's browser.
- Select Registrants.wo and click Open.
Table of Contents Next Section