beautypg.com

Adding custom behavior to talent, Providing default values in movierole, Adding custom behavior to talent 119 – Apple WebObjects 3.5 User Manual

Page 119: Providing default values in movierole 119

background image

Adding Behavior to Your Enterprise Objects

119

Adding Custom Behavior to Talent

Now add the

fullName

method to Talent and bind it to the browser.

1. Open

Talent.java

in Project Builder.

The class file declares instance variables for all of Talent’s class
properties (

firstName

and

lastName

) and implements set and get methods

for those instance variables.

2. Add the method,

fullName

, as follows.

public String fullName() { return firstName() + " " + lastName(); }

After you save,

fullName

appears in the object browser of WebObjects

Builder as a property of Talent.

3. Bind

talent.fullName

to the browser’s

value

attribute.

Providing Default Values in MovieRole

As discussed in “Specifying Default Values for New Enterprise Objects”
(page 87), there are two main ways to specify default values for new
enterprise objects without making explicit assignments:

Assign default values in the enterprise object class.

Specify default values using a display group.

For the Movie class, you specified default values using a display group. This
approach is also the more appropriate choice for the MovieRole class, but
you’ll use the other approach for MovieRole just to see how its done.

1. Open

MovieRole.java

in Project Builder.

2. Add the method,

awakeFromInsertionInEditingContext

, as follows.

public void awakeFromInsertionInEditingContext(EditingContext
context) {

super.awakeFromInsertionInEditingContext(context);

roleName = "New Role";

}

This method is automatically invoked right after your enterprise object
class creates a new MovieRole and inserts it into an editing context,
which happens when you use a display group to insert.