首页 > 解决方案 > 关于删除和应用 ADF 视图标准以编程方式查看对象的查询

问题描述

我有几个关于查看标准的问题

  1. 删除几个应用的视图条件后,我是否需要在应用相同或新的视图条件之前执行查询?
  2. 同样在应用每个视图条件后,我是否需要执行查询?
  3. 如果我要应用的第一个视图标准是使用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-adfjdeveloper

解决方案


这是一篇文章,我在其中讨论了如何在 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;
 }

要回答您的问题:

  1. 如果您的 vo 已设置为刷新,则不需要执行Query()。例如,如果您在迭代器上有一个 ppr。如果不是,您需要执行Query 来强制刷新您的迭代器。
  2. 您不需要在每个 applyViewCriteria 之后执行Query,尤其是当您使用辅助布尔参数 true 时,“在已应用的视图标准之上应用此视图标准”。它们都将作为层相互应用,并在您最后执行Query 时设置。
  3. 如果您不将辅助布尔参数添加为 true,则您的视图标准将是唯一应用的,所有其他的将被自动删除。

推荐阅读