Dive into Oracle ADF

Send me a mail
 Dive into Oracle ADF   Click to see the XML version of this web page.   (Updated: 2/3/2008; 8:12:23 PM.)
Tips and tricks from Steve Muench on Oracle ADF Framework and JDeveloper IDE

Search blog with Google:
 

Search BC4J JavaDoc:
 

May 2003
Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Apr   Jun

Get Firefox!

Friday, May 09, 2003

When writing validation methods on your entity objects, there are two basic approaches:

  1. Write code inside the attribute setter method for attribute-level validation, and inside an overridden validateEntity() method for entity-level validation, or
  2. Add attribute-level and/or entity level declarative method validation rules

I don't recommend approach number one because is complicates error handling, putting the onus on you as the developer to write much more error-handling code to maintain the correct framework behavior -- especially when you are using the BC4J framework's bundled exception mode (used automatically for BC4J/Struts applications).

The declarative validator approach is easier to maintain, offers a consistent mechanism for seeing what business rules have been defined on your object, and requires no additional error handling code to keep the bundled exception mode working correctly.

You can use the built-in "method validator" to add an attribute-level or entity-level business rule that is implemented by invoking a custom Java method in your entity object class. This method validator forces you to name your custom method with a prefix of the name "validate" so it makes all of the custom validation code show up together in the Java Class structure pane (conveniently). Also, having a declarative entry for custom method rules implemented is nice because it means that you can go to the validation panel of your entity object and get a birds-eye view of all business rules that are in effect, regardless of how they are implemented. The custom method validation is great if you are writing validation that is specific only to a single entity object. If you forsee some validations you do turning into a repeatable validation "pattern" (perhaps differing each time only by some parameterizable values), then you can create your own reusable business rules, and then many different entities can reuse those rules declaratively.

The BC4J framework comes with a handful of built-in rules, but the real powerful feature is that you can extend the set. The BC4J Toy Store Demo application features documented and explained examples of both method validator rules as well as a custom validation rule reused in multiple entity objects.

You can use the built-in method validator to declarative invoke validation methods that you write

 


2:36:48 PM    



© Copyright 2008 Steve Muench.