Sei sulla pagina 1di 33

Using ADF Business Components for Validation, Calculations, and LOV

Copyright 2008, Oracle. All rights reserved.

Objectives
After completing this lesson, you should be able to do the following: Build cascading lists of values (LOV) Enhance the application with calculations Validate foreign keys Employ Groovy expressions in validation

3-2

Copyright 2008, Oracle. All rights reserved.

Agenda
Cascading List of Values Transient Attributes and Calculations Entity Object Validation Failure Messages

3-3

Copyright 2008, Oracle. All rights reserved.

Cascading Lists
Use one list to determine the values of a second list: select a Manager, who works in the same department or has a job of MANAGER or PRESIDENT.
Employees in the Sales department Change department to Employees in the

Research
department

Research

3-4

Copyright 2008, Oracle. All rights reserved.

Creating the Basics


Configure view objects to support the lists. You can: Use existing view objects (VO) by creating different view criteria to support different lists Use entity-based VOs for data that may change when you want the list to reflect the changed data (such as adding a new department) Use non-entity-based VOs for static data Use bind variables to restrict the second list to the value specified in the first Add view accessors in the main (Emp) EO, to VO that are used for the lists Attach each list to a specific attribute to be populated

3-5

Copyright 2008, Oracle. All rights reserved.

Dependent List Example


The example contains two tables, EMP and DEPT. The EMP table contains two foreign keys: One to DEPT A recursive one back to EMP You create the default Business Components from tables for EMP and DEPT, adding components to AppModule.

3-6

Copyright 2008, Oracle. All rights reserved.

Creating the View Criteria


For the VO that is used for the dependent list, create a view criterion that uses a bind variable.

3-7

Copyright 2008, Oracle. All rights reserved.

Defining View Accessors to the List Data Sources


In the EO for the view that uses the lists, define view accessors to the views that are to be used as data sources for lists: Unrestricted: Using view criteria with value assigned to bind variable:

3-8

Copyright 2008, Oracle. All rights reserved.

Attaching the List VO to an Attribute


In the main VO that uses the lists: Enable a list of values for the attributes that use lists Select the appropriate view and attribute as a data source for each list

3-9

Copyright 2008, Oracle. All rights reserved.

Setting the List UI Hints


Set the Default List Type. Set the value displayed in the list to an attribute or attributes from the lists view object. Set the behavior for the required or not required value.

3 - 10

Copyright 2008, Oracle. All rights reserved.

Setting the List for the Dependent List


Follow the same process to add the dependent list.

3 - 11

Copyright 2008, Oracle. All rights reserved.

Agenda
Cascading List of Values Transient Attributes and Calculations Entity Object Validation Failure Messages

3 - 12

Copyright 2008, Oracle. All rights reserved.

Transient Attributes
They do not map to the database column. They are value holders to display the calculated data. After you add a transient attribute to the entity object, to make it a calculated attribute, you can define the calculation by one of the following methods:
Defining a Groovy or regular expression Writing Java code and using a SQL expression:

Enable a custom entity object class on the Java page of the Entity Object Editor, choosing to generate accessor methods. Write Java code inside the accessor method for the transient attribute to return the calculated value.

3 - 13

Copyright 2008, Oracle. All rights reserved.

Creating Transient Attributes


Create transient attributes to hold the calculated values. Define them at the entity object level or view object level.

3 - 14

Copyright 2008, Oracle. All rights reserved.

Entering a Calculation
In the Attribute Editor, to use a Groovy expression, select the Expression option and enter the calculation in the Value property. Set the dependencies to include all attributes in the expression.

3 - 15

Copyright 2008, Oracle. All rights reserved.

Testing the Calculation


If the attribute property of Updatable is set to Never, the field will be disabled in the tester.

3 - 16

Copyright 2008, Oracle. All rights reserved.

Agenda
Cascading List of Values Transient Attributes and Calculations Entity Object Validation Failure Messages

3 - 17

Copyright 2008, Oracle. All rights reserved.

Entity Object Validation


Validator Rule Name Description

Compare
List Range

Compares the attributes value with a literal value


Validates whether or not the value is in or is not in an LOV Validates whether or not the value is within a range of values

Length

Validates the values character or byte size against a size and operand (such as greater than or equal to)
Validates the data using Java regular expression syntax

Regular Expression

3 - 18

Copyright 2008, Oracle. All rights reserved.

Using Groovy for Validation


Groovy:
Is an agile and dynamic language for the JVM Increases developer productivity by using simple constructs and dot notation Compiles straight to Java bytecode, so you can use it anywhere you use Java

With Groovy, you can define validation rules, conditional validation, default values, and failure handling.
Equivalent Groovy Script
Sal * 0.10 Sal * 0.10

Java Code
((Number)getAttribute("Sal").multiply(ne w Number(0.10)) ((Date)getAttribute("PromotionDate")).co mpareTo((Date) getAttribute("HireDate")) > 0

Comparison of Java and Groovy Syntax


3 - 19

Copyright 2008, Oracle. All rights reserved.

Constraining Dependent Values


Use the Compare validation rule to constrain dependent values.

3 - 20

Copyright 2008, Oracle. All rights reserved.

Defining the Conditional Expression


On the Validation Execution tabbed page, you can use a Groovy expression to define when the validation should be executed.

3 - 21

Copyright 2008, Oracle. All rights reserved.

Agenda
Cascading List of Values Transient Attributes and Calculations Entity Object Validation Failure Messages

3 - 22

Copyright 2008, Oracle. All rights reserved.

Defining the Failure Message


You can use Groovy to display the attribute and its value in the error message, using message tokens.

3 - 23

Copyright 2008, Oracle. All rights reserved.

Storing Error Messages as Resources

3 - 24

Copyright 2008, Oracle. All rights reserved.

Validating Foreign Keys


You perform another type of validation on foreign keys. On the Validators panel of the Entity Object Editor, perform the following:
1. Select Entity. 2. Click Create new validator.

3 - 25

Copyright 2008, Oracle. All rights reserved.

Adding a Validation Rule


In the Add Validation Rule dialog box, select Key Exists from the Rule Type list.

3 - 26

Copyright 2008, Oracle. All rights reserved.

Managing Failures
On the Failure Handling tabbed page, enter the error message to be displayed when the validation fails.

3 - 27

Copyright 2008, Oracle. All rights reserved.

Testing the Validation


In the Tester, when you enter an invalid Foreign Key, the failure message displays.

3 - 28

Copyright 2008, Oracle. All rights reserved.

Script Expression Validation


For this example, you need to know the view accessor name between Dept and Emp. Create a Script Expression validation rule.

3 - 29

Copyright 2008, Oracle. All rights reserved.

Groovy Rule Definition


On the Rule Definition tabbed page, this code:
Converts the name to uppercase Determines if it ends in an S Validates if the Salary ends in a multiple of 5

The expression must return a Boolean true or false.

3 - 30

Copyright 2008, Oracle. All rights reserved.

Failure Handling
Groovy validation rules can conditionally raise one of several exceptions.

3 - 31

Copyright 2008, Oracle. All rights reserved.

Summary
In this lesson, you should have learned how to: Use two view objects to create dependent lists Add transient attributes to hold calculations Catch foreign key validations at the entity object level Create expression validations using Groovy

3 - 32

Copyright 2008, Oracle. All rights reserved.

Practice 3 Overview: Advanced ADF Business Components


This practice covers the following topics: Creating cascading lists Validating Entity objects

3 - 33

Copyright 2008, Oracle. All rights reserved.

Potrebbero piacerti anche