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

   

Performing Validation

Another element you'll likely want to add to your enterprise object classes is validation. For example, suppose that when a studio buys a new movie, you want to check to make sure that acquiring the movie won't cause the studio to exceed its budget. You could implement a method in the Studio class like the following:

Studio.java (server and client)

public void validateBudget(Number budget) throws
   EOValidation.Exception {
   if (budget.intValue() < 100) {
      throw new EOValidation.Exception
         ("A budget cannot be less than $100");
   }
}


Now when a studio buys more movies than it can afford, a panel displaying the message "A budget cannot be less than $100" appears when the user attempts to save the changes to the database.

Validation methods must be of the form validateAttribute. The validateBudget method is invoked by the validateValueForKey method, which is part of the EOValidation interface that uses the EOClassDescription class to provide default implementations of validation methods. These methods are invoked automatically by framework components such as EODisplayGroup and EOEditingContext. They are:

For more discussion of this topic, see the chapter "Designing Enterprise Objects" in the Enterprise Objects Framework Developer's Guide and the NSObject Additions class specification in the Enterprise Objects Framework Reference.


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