Skip to content

Instantly share code, notes, and snippets.

@CedricL46
Last active August 4, 2022 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CedricL46/6d810220eff7a6b87b95e0c0d3e8e975 to your computer and use it in GitHub Desktop.
Save CedricL46/6d810220eff7a6b87b95e0c0d3e8e975 to your computer and use it in GitHub Desktop.
How to apply a viewCriteria programmatically in ADF : https://cedricleruth.com/how-to-apply-a-viewcriteria-programmatically-in-adf/
/**
* Apply view criteria named MyViewCriteria to it's ViewObject
* by getting it through the binding iterator MyViewObjectIterator
* Full library : https://github.com/CedricL46/Oracle-ADF-and-JSF-Utils-libraries
*/
public void applyViewCriteriaOnViewObjectByIteratorName(String MyViewCriteriaName, String MyViewObjectIteratorName) {
try {
//Get The viewObject from the iterator define in the current binding context
ViewObject vo = this.getViewObjectFromIteratorName(MyViewObjectIteratorName)
//Get all it's ViewCriteria using the ViewCriteriaManager of the ViewObject
ViewCriteriaManager vcm = vo.getViewCriteriaManager();
//Get the specified View Criteria
ViewCriteria vc = vcm.getViewCriteria(MyViewCriteriaName);
//Apply the ViewCriteria to the ViewObject
vo.applyViewCriteria(vc);
//Note: If you need to apply this view criteria on top of already applied view criteria
//without removing them you can add the following boolean parameter :
//vo.applyViewCriteria(vc,true);
//That's all you need if the iterator is set to be refresh after this
//If not you can force the ViewObject to execute by uncommenting the following :
//vo.executeQuery();
} catch (NullPointerException e) {
//Log and warn for null
//Often occur when there is an error in the provided attributes
//(MyViewCriteriaName, MyViewObjectIteratorName)
} catch (Exception e) {
//Log and warn for other exceptions - Should never be needed
}
/**
* Useful function to get ViewObject from IteratorName
* The iterator need to have a least one binding define in the current page
* In this gist it's a private but i advice setting it as a public static in an utility class available for the whole Controller
*/
private ViewObject getViewObjectFromIteratorName(String MyViewObjectIteratorName) {
ViewObject vo = null;
try {
DCBindingContainer bindings = (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding iterator = bindings.findIteratorBinding(MyViewObjectIteratorName);
vo = iterator.getViewObject();
} catch (NullPointerException e) {
//Log and warn for null
//Often occur when there is an error in the provided attributes
//or if the iterator doesn't have a least one binding define in the current page
}
return vo;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment