在支持 bean 中执行查询并在 ADF 中更新 table 的正确方法

Proper way to execute a query in a backing bean and update a table in ADF

我有一个搜索按钮,它应该执行支持 bean 方法、执行查询然后刷新 table。我正在更改过程中查询的绑定参数。这样做的最佳方法是什么?

谢谢!

最好的方法是遵循 MVC 模型。为此,只需使用此算法:

创建视图对象接口的实现。在这里,您可以使用将传递给查询的参数来定义方法。为此,只需转到 Viewobject 定义 - "Java tab" - "Java classes" 编辑并选中 "Generate View Object class: YourViewObjectViewImpl" 和 "Include bind variable accessors",然后按确定按钮。找出 class YourViewObjectViewImpl.java 并使用您需要的参数实现方法。 例如你需要 2 个参数来刷新你的 VO:

public class YourViewObjectViewImpl extends ViewObjectImpl {

    // Generated method
    public void setA(Long value) {
        setNamedWhereClauseParam(value);
    }

    // Generated method
    public void setB(Long value) {
        setNamedWhereClauseParam(value);
    }

    // Your custom method
    public void refreshQuery(long a, long b) {
        this.clearCache();
        setA(a);
        setB(b);
        this.executeQuery();
    }
}

现在您需要使此方法对 ViewController 可见。在 ViewObject 定义的 java 选项卡中,按 "Client interface" 上的编辑,然后将穿梭 refreshQuery 方法移动到右侧。按确定。现在 Jdev 生成两个 classes,它们将帮助您使您的方法在 ViewController 项目中可见。

下一步是在页面定义绑定中定义您的 refreshQuery。 转到页面定义并按绑定面板上的 + 按钮。 Select 列表中的 methodAction。 Select 来自 AppModuleDataControl 的 ViewObject 和 select Operation 组合框中的 refreshQuery 方法。在带有参数的 table 中,您可以使用表达式语言定义值。例如#{viewScope.myBean.a} 和#{viewScope.myBean.b} 按确定。

现在您可以从 bean 中执行此方法,例如:

public class MyBean {
    public Long a = 0;
    public Long b = 0;

    public void refresh() {
        a = 1;
        b = 2;
        BindingContext bc = BindingContext.getCurrent();
        DCBindingContainer dcbc = (DCBindingContainer)bc.getCurrentBindingsEntry();
        dcbc.getOperationBinding("refreshQuery");
        dcbc.execute();
    }    
}