Search This Blog

Sunday, September 30, 2012

Build and Manage View Criteria dynamically in ADF

View Criteria :

Using Structured Where Clauses: View criteria are structured criteria that you can use to assemble a WHERE clause. Instead of changing WHERE clauses using string manipulation, you may find it more efficient to use view criteria to assemble complex WHERE clauses in conjunctive normal form.
To use structured WHERE clauses:

1. Instantiate the a ViewCriteria class by calling createViewCriteria() on the view object instance. For example, to create view criteria for the view object instance myOrdVO , you could use the following code:

ViewCriteria vc = myOrdVO.createViewCriteria();

2. For each view criteria row you will need, create a view criteria row by calling createViewCriteriaRow() on the ViewCriteria,

Example: ViewCriteriaRow cRow = vc.createViewCriteriaRow();


3. Set the requirements for each view criteria row by calling setAttribute() on the ViewCriteriaRow. Pass setAttribute() the name of the view object attribute and the SQL requirement to be applied to the attribute:

cRow.setAttribute("OrderTotal", "> 500");

cRow.setAttribute("CreditLimit", "> 2500");

cRow.setAttribute("PromotionId", "IS NOT NULL");


4. Add the rows to the view criteria by passing them to addElement() on the ViewCriteria:
vc.addElement(cRow);


5. Apply the view criteria to the view object instance by passing the ViewCriteria to applyViewCriteria():
myOrdVO.applyViewCriteria(vc);

At any time, you can do any of the following:

 Change the requirements in any row using setAttribute()

 Add further rows to the criteria using addElement()

 Remove rows from the criteria using removeElement()

 Construct and apply entirely different view criteria

 Unapply view critera by passing null to applyViewCriteria()

No comments:

Post a Comment