动态ViewObject的实现

对于一些基于多个表的viewObject或者是基于SQL的viewObject,可以通过获取当前的AM对象,拿到DBtransaction使用JDBC的方式查询,其优点是能够非常灵活地定制VO。具体实现代码如下:


    public ViewObject getDynamicViewObject(String sql) {
        FacesContext ctx = FacesContext.getCurrentInstance();
        ValueBinding vb =
            ctx.getCurrentInstance().getApplication().createValueBinding("#{data}");
        BindingContext bc =
            (BindingContext)vb.getValue(ctx.getCurrentInstance());

        
        //在DataBindings.cpx 文件中找到BC4JDataControl标记下的DataControl对象ID
        DataControl dc = bc.findDataControl("AppModuleDataControl");
        ApplicationModuleImpl am =
            ((ApplicationModuleImpl)(ApplicationModule)dc.getDataProvider());
       //通过 CallableStatement 可创建带参数的SQL查询
       // CallableStatement queryStatement =
       //     am.getDBTransaction().createCallableStatement(sql,
        //                                                  DBTransaction.DEFAULT);
        return am.getDBTransaction().createViewObjectFromQueryStmt(sql);

    }

你可能感兴趣的:(sql,jdbc,vb)