Populate Dynamic table and form using af:dynamicComponent and dynamic viewObject – Oracle ADF

Sharing is Caring

This post is about a common development requirement- Can we increase or decrease the number of fields, type of fields (columns in case of the table), data in fields at runtime?

Suppose I have to show data of Departments and Employees table on the page using only one af:table component. It means columns should be generated dynamically at run time depending on any defined condition
So for this requirement, I am using dynamic viewObject in model layer and af:dynamicComponent in the view layer
See the previous post about creating a dynamic view object-
Creating Dynamic View Object at Runtime programmatically – Oracle ADF

See step by step implementation-

    • Create Fusion Web Application and follow the link posted above to create dynamic viewObject, in short, create a view object using dual and a method in AMImpl to create dynamic viewObject from SQL query

 

/**Method to create viewObject using SQL query
 * @param query*/

public void createNewViewObject(String query) {
ViewObject dynVo = this.getdynamic1();
dynVo.remove();
this.createViewObjectFromQueryStmt("dynamic1", query);
this.getdynamic1().executeQuery();
}

 

    • Created a page and added an inputText to enter SQL query and a button to process that query and create dynamic viewObject at runtime

 

 

    • See Managed Bean code to process the query, the value of inputText is passed using component binding

private RichInputText sqlQueryBind;

public DynamicTableBean() {
}

/*****Generic Method to call operation binding**/
public BindingContainer getBindingsCont() {
return BindingContext.getCurrent().getCurrentBindingsEntry();
}

/**
 * Generic Method to execute operation Binding
 * */
public OperationBinding executeOperation(String operation) {
OperationBinding createParam = getBindingsCont().getOperationBinding(operation);
return createParam;

}

/**Method to create viewObject
 * @param actionEvent
 */
public void createViewObjectAction(ActionEvent actionEvent) {
if (sqlQueryBind.getValue() != null) {
OperationBinding ob = executeOperation("createNewViewObject");
ob.getParamsMap().put("query", sqlQueryBind.getValue().toString());
ob.execute();
}
}

public void setSqlQueryBind(RichInputText sqlQueryBind) {
this.sqlQueryBind = sqlQueryBind;
}

public RichInputText getSqlQueryBind() {
return sqlQueryBind;
}

 

    • Now dropped this dual viewObject on the page as dynamic form and dynamic table from Data Control (this snap is about creating form)

 

 

 

    • Next is to change the pageDef entry for this dynamic component, open pageDef and goto tree binding. there is an entry for nodeDefinition, there will be separate tree binding for form and table both (you should change both)

 <tree IterBinding="dynamic1Iterator" id="dynamic1">
            <nodeDefinition DefName="dynamictableapp.model.view.dynamicVO" Name="dynamic10"/>
        </tree>

Change this entry like this-

 <tree IterBinding="dynamic1Iterator" id="dynamic1">
            <nodeDefinition Name="dynamic10"/>
        </tree>

 

  • Now run this application and enter SQL query in box and press process button

 

Dynamic table

Download –Sample ADF Application

Cheers 🙂 Happy Learning

Related Posts

An Oracle ACE, Blogger, Reviewer, Technical Lead working on Oracle ADF

9 thoughts on “Populate Dynamic table and form using af:dynamicComponent and dynamic viewObject – Oracle ADF”

  1. excellent work , how can i change from outputtext to check box , then if i want make action on this check box on valueChangeListener?
    is that available or not?

    regards

  2. Hi Ashish,

    Super Explanation Man!!

    Just quick question, how to create dynamic table in updatable mode on UI (only when Status Code column in Dynamic table is 'E' then corresponding row should be in Editable mode).

    Jdev 12.1.3

    Thanks

  3. Hi Ashish,

    Super Explanation Man!!

    Just quick question, how to create dynamic table in updatable mode on UI (only when Status Code column in Dynamic table is 'E' then corresponding row should be in Editable mode).

    Jdev 12.1.3

    Thanks

  4. Hi Ashish,

    Can you please tell how to iterate the above created dynamic table and print each row data in the console.

    Thanks & Regards,
    Susanto

Leave a Reply

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