Creating Dynamic View Object at Runtime programmatically – Oracle ADF

Sharing is Caring

Dynamic View Object refers to creating ViewObject at Runtime using SQL statement,
ApplicationModuleImpl has a method to create ViewObject using SQL statement i;e createViewObjectFromQueryStmt .

This method creates a read-only viewObject at runtime when the query is processed in the method, In this post, I am going to show you that how can we use SQL queries at runtime to create a dynamic view object.

Follow these simple steps-

  • First, create a dummy ViewObject using dual 

 

  • Now add this ViewObject to Application Module
Dynamic View Object
  • Get application module using data control and call method to create dynamic ViewObject at runtime.

         Get Application Module-

public Object resolvElDC(String data) {
        FacesContext fc = FacesContext.getCurrentInstance();
        Application app = fc.getApplication();
        ExpressionFactory elFactory = app.getExpressionFactory();
        ELContext elContext = fc.getELContext();
        ValueExpression valueExp =
            elFactory.createValueExpression(elContext, "#{data." + data + ".dataProvider}", Object.class);
        return valueExp.getValue(elContext);
    }

public dynamicAMImpl getAm() {
dynamicAMImpl am = (dynamicAMImpl)resolvElDC("dynamicAMDataControl");
return am;
}

        Create dynamic View Object-

        ViewObject dynVo = getAm().getdynamic1();
        dynVo.remove();
        getAm().createViewObjectFromQueryStmt("dynamic1", query);

 

  • Now Run your application and put different SQL queries to generate and get row count of the view object

     

Download –Sample ADF Application

Cheers 🙂 Happy Learning

Related Posts

I’m an Oracle ACE, Blogger, Reviewer,
Technical Lead working on Oracle ADF

0 thoughts on “Creating Dynamic View Object at Runtime programmatically – Oracle ADF”

  1. Hi,
    There is a View Object which is created dynamically using the createViewObjectFromQueryStmt , In my query there might be Date columns available and i need to format those columns to different formats ( Format will be retrieved from Database based on user settings ) . This JSFF page is for reporting the data fetched from the dynamic query and it has sorting and filtering on , So this formatting of date should not affect the sorting and filtering of date columns . Since i am new to ADF i am not sure how to format these dates , It will be grateful if anyone can send me a sample project with the above scenario or else guide me on how to do this.

Leave a Reply

Your email address will not be published. Required fields are marked *