beautypg.com

Adding behavior to your enterprise objects, Specifying custom enterprise object classes, Adding behavior to your enterprise objects 117 – Apple WebObjects 3.5 User Manual

Page 117: Specifying custom enterprise object classes 117

background image

Adding Behavior to Your Enterprise Objects

117

6. Copy the

saveChanges

method from the

Main.java

class and paste it into the

MovieDetails.java

class:

public void saveChanges() throws Exception {

try {

this.session().defaultEditingContext().saveChanges();

}

catch (Exception exception) {

System.err.println("Cannot save changes ");

throw exception;

}

}

7. Bind

movieRoleDisplayGroup.insert

to the Insert/New image’s

action

attribute.

8. Bind the

saveChanges

method to the “Save to database” image’s

action

attribute.

9. Bind

movieRoleDisplayGroup.delete

to the Delete image’s

action

attribute.

Adding Behavior to Your Enterprise Objects

Right now, the Movies application maps all its entities to the
GenericRecord class. As the preceding sections illustrate, you can go quite
far in an application using just this default enterprise object class, but now
you need to add some custom classes to the Movies application.

In this section, you’ll learn how to:

Generate source code for a custom enterprise object class.

Provide default values in a custom enterprise object class.

You’ll create custom classes for the Talent and MovieRole entities. In the
Talent class, you’ll write a

fullName

method that concatenates a Talent’s first

and last names. You’ll use the method to populate MovieDetail’s browser
element. In the MovieRole class, you’ll provide default values for newly
inserted MovieRoles so they don’t show up in the list of movie roles as a
blank line.

Specifying Custom Enterprise Object Classes

Unless you specify otherwise, EOModeler maps entities to the
GenericRecord class. When you want to use a custom class instead,
you need to specify that custom class in the model.