Last active
August 4, 2022 11:28
-
-
Save CedricL46/0d6d15abf8b52658237000f9b96a74ee to your computer and use it in GitHub Desktop.
How to unApply a viewCriteria programmatically in ADF : https://cedricleruth.com/how-to-unapply-a-view-criteria-programmatically-from-a-view-object-in-adf/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Unapply a 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 UnApplyViewCriteriaOnViewObjectByIteratorName(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(); | |
//remove the specified viewCriteria | |
boolean unApplyResult = vcm.removeApplyViewCriteriaName(MyViewCriteriaName); | |
//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 | |
} | |
/** | |
* Full library: https://github.com/CedricL46/Oracle-ADF-and-JSF-Utils-libraries | |
* 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