如何解决关于以编程方式删除和应用 ADF 查看条件以查看对象的查询
我有几个关于查看标准的问题
- 删除一些应用的视图条件后,我是否需要执行查询 在应用相同或新的查看标准之前?
- 此外,在应用每个视图条件后,是否需要执行查询?
- 如果我想应用的第一个查看条件是使用
testVO.applyViewCriteria(vc);
应用的,我之前是否需要删除不需要的查看条件,还是会applyViewCriteria(vc)
删除所有现有的查看条件?
我在下面的代码中试图做的是删除任何应用的视图标准,然后应用我想要应用的新视图标准。
testVO.getViewCriteriaManager().removeApplyViewCriteriaName("findByvc1");
testVO.getViewCriteriaManager().removeApplyViewCriteriaName("findByvc2");
testVO.getViewCriteriaManager().removeApplyViewCriteriaName("findByvc3");
//testVO.executeQuery();
ViewCriteria vc = testVO.getViewCriteriaManager().getViewCriteria("findByvc1");
VariableValueManager vm = testVO.ensureVariableManager();
vm.setvariableValue("vc1Var",123);
testVO.applyViewCriteria(vc);
//testVO.executeQuery();
ViewCriteria vc1 = testVO.getViewCriteriaManager().getViewCriteria("findByvc3");
vm.setvariableValue("vc3Var","test");
testVO.applyViewCriteria(vc1,true);
testVO.executeQuery();
解决方法
这是我讨论如何在 Oracle 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
*/
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;
}
回答您的问题:
- 如果您的 vo 已设置为刷新,则不需要 executeQuery()。例如,如果您在迭代器上有一个 ppr。如果不是,您需要执行查询来强制刷新您的迭代器。
- 您不需要在每个 applyViewCriteria 之后执行查询,尤其是当您使用辅助布尔参数为 true 时,它“在已应用的视图标准之上应用此视图标准”。它们都将作为层相互应用,并在您最后执行查询时进行设置。
- 如果您没有将次要布尔参数添加为 true,您的视图标准将是唯一应用的标准,所有其他标准都将被自动删除。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。