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/0d6d15abf8b52658237000f9b96a74ee to your computer and use it in GitHub Desktop.
Save CedricL46/0d6d15abf8b52658237000f9b96a74ee to your computer and use it in GitHub Desktop.
/**
* 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