Tuesday, March 15, 2011

View Criteria Explained....

As you know, View Criteria's are additional where clause to be base query.
Applying View Criteria .....
1. Declaratively ...

In Edit View object Instance dialog of App Module , where you can apply view criteria to the view object. (by shuttling the view criteria) . Refer the picture below...



But this view criteria gets applied ONLY one time (as soon as the view object is instantiated and initialized). If this view criteria gets erased (replaced with other view criteria etc...), it wont be there in the view object query for execution..


2. Programmatically...

ViewCriteria applyVC = myViewObject.getViewCriteria("ViewCriteriaName");
myViewObject.applyViewCriteria(applyVC);
myViewObject.executeQuery();

Applying Multiple view Criteria's:
When multiple view criteria's are applied to the view object, the view criterias gets appended or replaced depending upon the way you use applyViewCriteria API

Replacing Existing view criteria's :
myViewObject.applyViewCriteria(applyVC) or myViewObject.applyViewCriteria(applyVC,false) - will erase all previously applied view criterias and apply ONLY the current view criteria.

Appending to the Existing view criteria:
myViewObject.applyViewCriteria(applyVC, true) - will append this view criteria to the existing view criteria(s) which is applied already.

A note on Vo.ExecuteQuery()
ExecuteQuery statement will always fetch the rows from the DB by executing the query in the View object. vo.getQuery() provides current query in the view object. Execute query wont apply the query against current view object rows, but instead it always fetches from the DB.

vo.removeApplyViewCriteriaName()
Unapply the view criteria if it is applied. The view criteria will continue to be managed by this manager.
(which means you can apply this view criteria whenever you require in the future).

vo.removeViewCriteria()
Removes the view criteria from this manager. If it is applied it is first unapplied and then removed. (which means you cant apply this view criteria to the view object as it will be removed from the view criteria manager).
For example the below code returns null after removeViewCriteria has been applied.

ViewCriteria applyVC = myViewObject.getViewCriteria("removedViewCriteria")

Please be cautious in using in this method. If your intent is to unapply the view criteria use vo.removeApplyViewCriteriaName method

vo.clearViewCriterias()
Unapplies and removes all view criteria, both applied and unapplied from the manager. You cant apply any view criteria again to this view object.

For example the below code returns null after clearViewCriterias() has been applied.

ViewCriteria applyVC = myViewObject.getViewCriteria("ANY_VIEW_CRITERIA")

Please be cautious in using in this method.

myViewObject.applyViewCriteria(null)
This above statement is as good as the statement is not issued. Neither it unapplies existing view criterias nor it removes the view criterias.

4 comments: