Documentation Archive Developer
Search
PATH  Documentation > WebObjects 4.5 > Getting Started With WebObjects


   

Creating a Detail Display Group

You can create a detail display group several different ways. You can write a declaration for it in Project Builder, or you can use WebObjects Builder's Add Variable/Method command. But the easiest way to create a detail display group is by dragging a relationship from EOModeler into your component, as described below.

  1. In EOModeler's tree view, expand the Movie entity.

  2. Drag the Movie's toMovieRole relationship from the tree view into the MovieDetails component's object browser.

    An Add Display Group panel opens.

  3. In the Add Display Group panel, change the name to
    movieRoleDisplayGroup.

  4. Click Add and Configure.

    The Display Group Options panel opens so you can immediately configure the newly created display group.

    Ensure that the "Has detail data source" box is checked. This means that movieRoleDisplayGroup gets its objects from a EODetailDataSource object.

    All display groups use some kind of data source to fetch their objects. A data source is an object that exists primarily as a simple means for a WODisplayGroup to access a store of objects. It's through a data source that a display group fetches, inserts, updates, and deletes database records.

    An EODetailDataSource is a subclass of EODataSource that's intended for use in master-detail configurations. A detail data source keeps track of a master object and a detail key. The master object is typically the selected object in a master display group, but a master display group isn't strictly required. The detail key is the name of the relationship on which the master-detail configuration is based. When a detail display group asks its data source to fetch, the EODetailDataSource simply gets the destination objects from the master object as follows:

    detailObjects = masterObject.valueForKey(detailKey);

    In your master-detail configuration, the master object is the selected Movie, and the detail key is toMovieRole. When movieRoleDisplayGroup asks its data source for its MovieRole objects, the detail WODisplayGroup returns the objects in the selected Movie's toMovieRole array of MovieRoles. Similarly, when MovieRole objects are inserted or deleted in movieRoleDisplayGroup, they are added and removed from the master object's toMovieRole array.

  5. Set the display group to sort alphabetically by roleName.

  6. Check the "Fetches on load" box.

    When "Fetches on load" is selected, the display group fetches its objects as soon as the component is loaded into the application. You want this feature in the MovieDetails page so that users are immediately presented with the selected movie's roles. In contrast, the Main page does not fetch on load; it shouldn't present a list of movies until the user has entered search criteria and clicked Match.

  7. Click OK.

  8. In Project Builder, modify MovieDetail's setSelectedMovie method to look like the following:

    public void setSelectedMovie(EOEnterpriseObject newSelectedMovie) {
       selectedMovie = newSelectedMovie;
       movieRoleDisplayGroup.setMasterObject(newSelectedMovie);
    }

    With this addition, whenever a user navigates to the MovieDetails page, setSelectedMovie updates the master object of the movieRoleDisplayGroup so it displays the corresponding MovieRole objects.


© 1999 Apple Computer, Inc. – (Last Updated 24 Aug 99)