Documentation Archive Developer
Search
Table of Contents Previous Section

Add a search page

The Database Wizard can also set up pages for searching the database. In this section, you'll create a page that allows you to search for movies that match criteria you specify.

You can insert, update, and delete movies with this page the same way you do in Main. Not surprisingly, the steps for creating the search page are very similar to those for creating Main.

Create a component

  1. Bring the Movies application window to the front.

  2. Click the Component tab.

  3. Click the plus button.

  4. Type MovieSearch as the name of the component.

Run the Database Wizard

Activate the wizard from the MovieSearch component window. You'll perform the same steps you did for the Main component, except this time you'll:

  1. In the Database Wizard's Specify a model file panel, click Browse to locate the model file.

    When you created the Main page, you created a new model file with the Database Wizard. The wizard saved the model in the Movies application directory. When you run the Database Wizard this time, you can specify that model file.

  2. In the Open panel, navigate to the Movies.woa directory.

    A model file is actually a directory, or file package, that contains a collection of files that shouldn't be separated. A model's file package has the extension .eomodeld (for eomodel directory).

  3. Select the directory with the extension .eomodeld.

    For Mach Users Only: WebObjects application directories such as Movies.woa are also file packages. Ordinarily you can't see the contents of a .woa directory in the Workspace File Viewer, in Open panels, or in Save panels. To select the model file in the Database Wizard's open panel, bring the Workspace File Viewer to the front. Navigate to your Movies.woa application directory, and choose File Open as Folder. The Workspace opens a new viewer window that's focused on the contents of the Movie.woa directory. Select the model file package, and drag it into the Database Wizard's Open panel.

  4. In the Choose an entity panel, select the Movie entity.

    Model files store database login and primary key information, so when you run the Database Wizard this time, it doesn't prompt you with a Choose Adaptor panel, a login panel, or a Choose a Primary Key panel.

  5. Choose the Selected Record and Matching Records layout options.

    As you can see in the Choose a layout panel's page preview, the Matching Records option generates a database search form in which users can specify record-matching criteria.

  6. Choose the same attributes to display: title, category, rating, dateReleased, and revenue.

  7. Choose the title attribute to display on the hyperlink.

    When you choose the Matching Records layout option, you must tell the Database Wizard what attributes to put in the query form.

  8. Select title, category, and rating as the attributes on which to match.

    As before, the Database Wizard designs a functional page, but this one allows you to search the database for a movie that matches criteria you specify. It again uses a WODisplayGroup to not only fetch objects from the database, but also to build the query.

Add date and number formats

  1. Add the date format "%d %b %Y" to the dateReleased text field.

  2. Add the number format "$ #,##0.00" to the revenue text field.

Change the display group options

  1. Open the DisplayGroupEditor for the MovieSearch component's movies variable.

  2. Deselect the Fetches on load option.

  3. Set the sort order as you did for the Main component.

Notice that you're configuring this movies display group differently than you did the Main page's display group. The Main page had Fetches on load selected and its Entries per batch was set to 10. MovieSearch has Fetches on load deselected, and its batch size is 0.

When Fetches on load is selected, the display group fetches records from the database when the component is loaded into the application. You want this feature in the Main page so that your users are immediately presented with a list of movies when they start the application. In contrast, the MovieSearch page should not present a list of movies until the user has entered search criteria and clicked Match. Thus, you deselect Fetches on load so that the movie list is not displayed until the query is performed.

Entries per batch specifies the number of records the display group displays at a time. When this number is 0, as it is in the MovieSearch page, the display group won't display search results in batches. Instead, all the movies that match a user's search criteria are displayed at once. In Main, the batch size is 10 and you use the Next Page and Previous Page buttons to page through the results. The Database Wizard set the batch size to 10 for the Main page because you specified the Paginated 10 per page option when you created it. The Database Wizard sets the batch size to 0 for all other page layout options.

Specify page transitions

Now your application needs a way for users to get to the MovieSearch page from the application's Main page. To provide it, add a hyperlink to the Main component that opens the MovieSearch page.

  1. In the Main component window, place the cursor at the bottom of the page below the horizontal line.

  2. Drag a Hyperlink from the Abstract Elements palette into the component window.

  3. Select the word "Hyperlink" and type Movie Search in its place.

  4. In the hyperlink bindings inspector, set the pagename attribute to "MovieSearch".

    The pagename binding is a mechanism for navigating to another page. By setting the attribute to "MovieSearch", you're telling the application to open the MovieSearch page when the hyperlink is clicked.

    A user should also be able to get back to the Main page from the MovieSearch page.

  5. Create a hyperlink labeled "Browse Movies" in the MovieSearch page that opens the Main page.

Save and run your application

Reload the Main page in your web browser to get the Movies application to load the new Movie Search link. In the Movie Search page, try searching for movies that match the word "The." Notice that the Movies application locates only movies that begin with the string "The" as oppoed to containing the string "The".

  1. Using the DisplayGroupEditor, change the qualification mode for the movies display group.

    How does the qualification mode affect searching in the Movies application?

Table of Contents Next Section