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

Table of Contents Previous Section

Configuring the Browser

Similar to the way you created bindings for a repetition, create your browser's bindings.

  1. Bind talentDisplayGroup.displayedObjects to the browser's list attribute.

  2. Bind talent to the browser's item attribute.

  3. Bind talent.lastName to the browser's value attribute.

    The value attribute tells the browser what string to display. For each item in its list, the browser evaluates the item's value.

    The browser in the MovieDetails page should display the actors' full names, but there isn't an attribute for full name. In the next section, you'll create a custom Talent class that implements a fullName method, but for now just use talent.lastName as the value attribute.

    A browser also has a selections attribute that should be bound to an array of objects. A browser's selection can be zero, one, or many objects; but in the Talent browser, the selection should refer to a single object. Consequently, you need to add two methods to manage the browser's selection: one to return an array containing the selected Talent and one to set the selected Talent from an array object.

  4. Add the method talentSelection to the MovieDetails.java class as follows:
    public NSArray talentSelection() {
    	EOEnterpriseObject aTalent;
    	EOEnterpriseObject aMovieRole = 
    (EOEnterpriseObject)movieRoleDisplayGroup.selectedObject();
    if (aMovieRole == null){ return null; } aTalent = (EOEnterpriseObject)aMovieRole.valueForKey("toTalent"); if (aTalent == null){ return null; } else { return new NSArray(aTalent); } }

    Because the browser expects an array for its selections attribute, this method packages the selected MovieRole's talent object in an array. If the selected MovieRole object is null, talentSelection simply returns null to indicate that the browser shouldn't set a selection.

  5. Add the method setTalentSelection as follows:
    public void setTalentSelection(NSArray talentArray){
    	if (talentArray.count() > 0){
    		EOEnterpriseObject aMovieRole = 
    (EOEnterpriseObject)movieRoleDisplayGroup.selectedObject();
    EOEnterpriseObject selectedTalent =
    (EOEnterpriseObject)talentArray.objectAtIndex(0);
    aMovieRole.addObjectToBothSidesOfRelationshipWithKey( selectedTalent, "toTalent"); } }

    Again because the browser uses an array for its selections attribute, the setTalentSelection method must take an array as its argument. If talentArray's count is nonzero, then this method sets the selected MovieRole's talent to the first object in the array. Note that by default, a user can't select more than one actor in a browser.

    With the addition of these methods, WebObjects Builder now displays talentSelection in MovieDetail's object browser.

  6. Bind talentSelection to the browser's selections attribute.

Table of Contents Next Section