Configuring the Browser
In a way similar to the way you create bindings for a repetition, create your browser's bindings.
- Bind talentDisplayGroup.displayedObjects to the browser's list attribute.
- Bind talent to the browser's item attribute.
- Bind talent.lastName to the browser's value attribute.
- Add the method talentSelection to the MovieDetails.java class as follows:
- Add the method setTalentSelection as follows:
- Bind talentSelection to the browser's selections 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 a vector 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 a vector containing the selected Talent and one to set the selected Talent from a vector object.
public ImmutableVector talentSelection () { EnterpriseObject aTalent; EnterpriseObject aMovieRole = (EnterpriseObject)movieRoleDisplayGroup.selectedObject(); if (aMovieRole == null) { return null; } aTalent = (EnterpriseObject)aMovieRole.valueForKey("talent"); if (aTalent == null) { return null; } else { EnterpriseObject talentArray[] = {aTalent}; return new ImmutableVector(talentArray); } }
Because the browser expects a vector for its selections attribute, this method packages the selected MovieRole's talent object in a vector. If the selected MovieRole object is null, talentSelection simply returns null to indicate that the browser shouldn't set a selection.
public void setTalentSelection(ImmutableVector talentVector) { if (talentVector.size() > 0) { EnterpriseObject aMovieRole = (EnterpriseObject)movieRoleDisplayGroup.selectedObject(); EnterpriseObject selectedTalent = (EnterpriseObject)talentVector.firstElement(); aMovieRole.addObjectToBothSidesOfRelationshipWithKey( selectedTalent, "talent" ); } }
Again because the browser uses a vector for its selections attribute, the setTalentSelection method must take a vector as its argument. If talentVector's size is nonzero, then this method sets the selected MovieRole's talent to the first object in the vector. 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.
Table of Contents Next Section