PATH  Documentation > WebObjects 4.5 > Creating a Java Client Application: A Tutorial

   

Providing Default Values for Newly Inserted Objects

When new objects are created in your application and inserted into the database, it's common to assign default values to some of their properties. For example, you might decide to assign newly created Studio objects a default budget (the budget is the amount a studio is allowed to spend on new movies).

To assign default values to newly created enterprise objects, use the method awakeFromInsertion . This method is automatically invoked right after your enterprise object class creates a new object and inserts it into an EOEditingContext.

The following implementation of awakeFromInsertion in the Studio class sets the default value of the budget property to be one million dollars:

Studio.java (server and client)

public void awakeFromInsertion(EOEditingContext ec) {
   super.awakeFromInsertion(ec);
   if (budget() == null)
      setBudget(new BigDecimal("1000000"));
}

When a user clicks the Add Studio button in the StudioManager application, a new record is inserted, with "$1,000,000.00" already displayed as a value in the budget column.


© 1999 Apple Computer, Inc. – (Last Updated 13 Sep 99)