Skip to main content
This revision made February 14, 2013 10:21, by steven.davelaar

ADF Samples - Validation and Business Rules

Main Table of Contents

ABA216 Conditional Validation in ADF BC {] 24-DEC-2012
ABA215 Skip Validation for ADF Required Tabs {] 21-DEC-2012
ABA203 ADF BC View Accessor To Centralize Business Logic Processing {] 09-NOV-2012
ABA197 Transaction Level ADF BC Entity Validation {] 22-OCT-2012
ABA190 What To Do When ADF Editable Table Misbehaves {] 09-SEP-2012
ABA187 New Record Master-Detail Validation and ADF BC Groovy Use Case {] 26-AUG-2012
ABA169 ADF 11g R2 Model Layer Validation Functionality {11.1.2] 30-MAY-2012
JPU078 Validating The Entity Collection When You Commit the Transaction {] 09-OCT-2011
ABA121 Difference Between Fetched Row Count and Just Row Count {11.1.1.x] 28-AUG-2011
ABA116 Unique Key Validation for LOV Based on Reference Attribute {11.1.1.x] 11-JUL-2011
JPU051 Updating supporting business data before committing the transaction {] 24-DEC-2010
JPU044 Converting user input to uppercase {] 03-NOV-2010
JPU043 Preventing user input on a fusion web page when the server is busy {] 15-OCT-2010
ABA054 Implementing Custom Generic PL/SQL Validator in Oracle ADF {11.1.1.x] 14-APR-2010
JPU016 Customizing the execution of <af:fileDownloadActionListener> to validate user input {] 20-JAN-2010
SMU159 Using ViewAccessor to Perform Attribute-Level Validation {] 11-JAN-2010
This example illustrates two techniques to perform an attribute-level validation based on a view-accessor with a bind variable that needs to be bound to the value that is attempting to be set. For an entity-level validation, you can use a view accessor based list validator for this purpose. However, for the attribute-level use case - since you cannot refer to the newValue expression in the view accessor bind variable default Groovy expression - you need to either use a groovy expression validator, a Java method validator, or a custom validation rule. This workspace provides examples of the first and the last of these three options. The Java method validation alternative is left as an exercise to the reader. The Emp EO has two view accessors: CheckDivisibilityBy3 based on view object definition test.ValidationViewObject, configured to have the VarModulo value set to 3, and CheckDivisibilityBy7 based on the same view object, configured to have the VarModulo value set to 7 The attribute-level Groovy validator on the Sal attribute sets the value of the VarValue bind variable on the view accessor, then executes the query. It returns value if the view accessor's first() function returns a non-null result (i.e. at least one row was found). The example also illustrates a more generic approach that doesn't rely on Groovy. I created a new, reusable validation rule called AttrLevelViewAccessorValidator. I've used an instance of it on the Comm attribute, declaratively configuring the validation rule beans two properties: attrNameToBindNewValueTo = "VarValue" and viewAccessorName = "CheckDivisibilityBy7". Run the AM in the tester, and verify that you must enter a Sal value that is divisible by 3 and a Comm value that is divisible by 7. Of course, the example view object would normally be a more interesting query with one or more bind variables going against a table other than DUAL, but this simple query hopefully will get the basic idea across. If the value being validated were the key attribute of the target view object, you could have used the "Key Exists" validator based on a view accessor instead. This approach is valid when the query you need to validate needs to lookup something that is not the key attribute in the target VO used for validation.
ABA035 Conditionally Required Fields in Oracle ADF Faces Rich Client {11.1.1.x] 30-DEC-2009
SMU155 Avoid Adding a New Row to a Table Until Its Valid {] 26-DEC-2009
This example illustrates an approach to prevent a newly-created row from getting automatically added to a view object's rowset (shown in a table) until it passes all validation rules. Typically a newly-created row will be added to a rowset for any view object based on the same entity object. This example contains a framework extension class for entity objects NotifyChangeOnValidatedEntityImpl and a framework extension class for view objects OnlyAddNewRowIfValidViewObjectImpl. The entity framework extension class overrides the validateEntity() framework method to send an attribute change notification after the entity object successfully passes validation. The view object framework extension class exposes getter and setter methods for a boolean property named onlyAddNewRowIfValid and the overridden rowQualifies() method ensures that a new row does not qualify for inclusion in the view object's rowsets unless it is valid. The AppModuleImpl class overrides the prepareSession() method to set the property on the DeptView1 view object instance. To run the demo, run the view1.jspx page. Click (Create) to create a new row. A data entry form appears at the top of the page. To cause a validation error to occur, leave the fields blank, or try entering a Dname value of upper-case X and a Loc value of upper-case Y. Notice that until the row validates, it's not added into the table.
LJE020 Implementing conditionally required input fields – by playing client side hide and seek {11.1.1.x] 17-DEC-2009
ABA031 Overriding IsAttributeUpdateable Method for Conditional Rendering {11.1.1.x] 06-DEC-2009
SMU153 Validating Exactly One Detail Row of a Given Type {] 04-NOV-2009 Custom schema
This example illustrates two techniques for validating that a parent entity contains exactly one composed child entity of a given type. Start by running the CreateTables.sql script to create the EMAIL_MESSAGE and EMAIL_MESSAGE_RECIPIENTS tables. The example is a simple "Create an Email" application that allows you to create a new email message and add one or more recipients. Each recipient is of a particular RecipientType (P=Primary, C=CC, B=BCC). The rule being enforced is that there must be exactly one recipient of type "Primary". The validation is performed by an entity-level Script Expression validator on the parent Email entity object. This validator uses Groovy code to work with a view accessor named ValidateOnePrimary which is of type EmailRecipientsView and has the design-time-applied view criteria named PrimaryRecipient (criteria mode "Both") applied to it. This view criteria filters based on the MessageId and the RecipientType='P'. The view accessor is configured to pass the value of the current Email entity's Id attribute as the value of the view criteria's VarMessageId bind variable. Notice that the script validator allows multiple error messages to be defined. The validator's Groovy script executes the view accessor's query, raises one error using adf.error.raise(MESSAGE_KEY) if there are no rows returned and another error if more than one row is returned. If the email and its recipients validate successfully, then they are saved to the tables, but note that no real email is sent anywhere. The default expression for the EmailRecipient.RecipientType attribute uses an alternative approach to the view accessor in order to conditionally assign the default recipient type for a newly created EmailRecipient entity. The default expression is Email.Recipients.count("RecipientType == 'P' ? 1 : null") == 0 ? 'P' : 'C' which accesses the parent email message using the reverse association accessor named Email then accesses its rowset of recipients by references that email entity's Recipients association accessor attribute. Since the value of that expression is a RowSet we can use one of the built-in rowset, in-memory aggregation functions to calculate the count of the child EmailRecipient entity instances which have a RecipientType equal to P. The count() rowset aggregate function evaluates its String argument as a Groovy expression in the context of each row in the rowset over which it iterates. If the expression evaluates to null, then the count does not include that row. If the expression evaluates to non-null, then that row is counted. Finally, it uses a ternary expression so that if the count of EmailRecipient instances having RecipientType equals to P is zero, then it returns the default value of P, otherwise it returns the default value of C to represent a recipient being copied on the mail. The Email entity object includes the MessageText attribute of type ClobDomain, and both the Email.SenderEmail and EmailRecipient.RecipientEmailAddress attributes use a custom domain type EmailAddress which validates the format of an email address. The NewMailMessage.jsff page fragment uses the special <f:converter converterId="oracle.genericDomain"/> component to enable JSF to work properly with these three domain-valued attributes. The MailServer application module defines the custom method createNewMailAndPrimaryRecipient() which creates a new email message and the first email recipient row. The method is exposed on the client interface so that the default method call activity of the create-new-email bounded task flow can invoke it declaratively to prepare the service layer for the creation of a new email. The CustomViewObjectImpl class implement a generic feature to conditionally have rows in a view object's default rowset be inserted at the end. For view objects using this framework extension class as their base class, the feature "kicks in" if the VO has the "InsertRowsAtEnd" custom property set to some non-null value like "true". The EmailRecipientsView in the example uses this framework extension class as its base class and has this custom property set. To run the example, run the TestPage.jspx. You'll need to login as either user userone or usertwo, both of whose password is welcome1. Click on the button to create an "email" and then click (Send) to test the validation.
ABA022 Business Logic Groups in Oracle ADF 11g {11.1.1.x] 03-NOV-2009
LJE008 Validation of Uploaded Files with the inputFile component {11.1.1.x] 14-SEP-2009
JPU004 How to Skip Validation? {] 22-AUG-2009
ACC008 How-to use Captcha with ADF Faces and Oracle ADF {11.1.1.x] 17-JUL-2009
ACC010 How-to create a character input counter for text fields {11.1.1.x] 15-SEP-2008
Difference compared to previous revision
(No Modifications)
Please Confirm