Specifying default values for new enterprise objec – Apple WebObjects 3.5 User Manual

Page 87

Advertising
background image

Refining Main.wo

87

Specifying Default Values for New Enterprise Objects

When new enterprise objects are created in your application, it’s common
to assign default values to some of their properties. For example, in your
Movies application it makes sense to assign a default value for the

title

attribute so a new movie won’t be displayed in the list of movies as a blank
line.

You could write an action method for the Insert/New button instead of
binding it directly to the display group

insert

action method. In the custom

action, you would create a new Movie object, assign default values to it, and
then insert the new object into the display group. However, there are two
additional 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 a particular situation, one of the approaches is usually better than the
other. If the default values are intrinsic to the enterprise object, assign them
in the enterprise object class. For example, consider a Member class with a

memberSince

property. It’s likely that you would automatically assign the

current date to

memberSince

instead of forcing a user to supply a value. You’ll

see how to use this technique in “Adding Behavior to Your Enterprise
Objects” (page 117).

On the other hand, if the default values are specific to an application or to a
particular user interface, explicitly initialize the object in code or specify the
default values using a display group. In the Movies application, the need for
default values is motivated by Main’s user interface: you need to provide a
default value so users can tell when a newly inserted record is selected. In
another situation, you might not want a new movie to have a default title;
you might instead want a new movie’s title to be blank.

An image in this column means that the variable can be initialized
from the component’s archive.

A

means that initialization parameters are already set. The variable

is created and initialized from the archive as a part of the component’s
initialization.

A

means that no initialization parameters have been set, and so

the variable isn’t automatically created. Double-click the variable to
configure it and add it to the archive.

Advertising