Forum Stats

  • 3,852,354 Users
  • 2,264,094 Discussions
  • 7,905,044 Comments

Discussions

Create ADF Table at runtime

852806
852806 Member Posts: 160
edited Feb 7, 2012 1:53PM in JDeveloper and ADF
Hi,

I am trying to create ADF table at run time. Initially I tried to include all the tables at design time. Then I turned the setVisible property to false. Then , based on the condition, I turned it to true at runTime, so that to give the effect of the table getting created at run time.

But now, I would like to know , is there any option to extract the table component from the ViewObject or from the iterator, at run time.

say,
I have my ViewObject like this.

DCIteratorBinding dcIter=(DCIteratorBinding)bindings.getControlBinding("Table1View1Iterator");
ViewObject vo=dcIter.getViewObject();


Now, I have a panel, 'pb1'. I am able to add input boxes at run time. Now I want to add the table that corresponds to the above View also at run time.

Could someone pls give me the suggestion..


Thanks,
Sabarisri. N

Answers

  • 851178
    851178 Member Posts: 163
    Hi,

    check this,

    This may give you idea,

    http://gopsatora.blogspot.in/2011/11/adding-multiple-times-set-of-adf.html

    Here, I have binded the RichInputText i nthe pojo, similarly you can bind the table and you can iterate and get the view object

    -
    Gopi
  • Abhijit Dutta
    Abhijit Dutta Member Posts: 934
    Hi,

    Your question is not clear to me.
    But now, I would like to know , is there any option to extract the table component from the ViewObject or from the iterator, at run time.
    can you explain a bit more

    ~Abhijit
  • 852806
    852806 Member Posts: 160
    Hi Abhijit,

    My use case is like this. I have a select one list box, in which I have a list of the table names. The user when he clicks the option, he shd be able to see that table below. For this,

    I would like to create a ADF table component to a panel at run time.

    So, now I have only the view instances like Table1View1, Table2View1 ,etc. Also, I have corresponding iterators. Usually, from the iterator, we can get the view object. but , I need a RichTable object for that view instance. so that, I could add this component to my panel.

    Thanks,
    Sabarisri. N
  • Abhijit Dutta
    Abhijit Dutta Member Posts: 934
    Hi,

    how it would be to make visible/invisible the tables(within panel) based on the selection?

    let's assume that you drag and drop the VO1 and VO2 in Panel1 and Panel2 respectively. what is the need of creating table dynamically from bean then?

    ~Abhijit
  • 852806
    852806 Member Posts: 160
    what is the need of creating table dynamically from bean then?
    :) Hi, I am telling that, I used the 'setVisible' property initially. Now I would like to change my approach. So, Now, no more tables in the design time of my page. I am going to add the tables to my panel at run time.

    Now, I have only the view names for each table. With this is there any possibility to obtain RichTable object to add to my panel component.


    Thanks,
    Sabarisri. N
  • Abhijit Dutta
    Abhijit Dutta Member Posts: 934
    well, in that case you can create table dynamically from managed bean. I am giving you a sample code which add row dynamically to a table on click of "Add" button.

    jspx code:
    <af:document id="d1" title="XXXX">
          <af:form id="f1">
            <af:commandButton text="Add" id="cb1" action="#{MyBean.add}"/>
            <af:table varStatus="rowStat" summary="table"
                      value="#{MyBean.collectionModel}"
                      rows="#{MyBean.collectionModel.rowCount}"
                      rowSelection="none" contentDelivery="immediate" var="row"
                      rendered="true" id="t1">
              <af:forEach items="#{MyBean.columnNames}"
                          var="name">
                <af:column sortable="true" sortProperty="#{name}"
                           rowHeader="unstyled" headerText="#{name}"
                           inlineStyle="width:100px;" id="c1">
                  <af:activeOutputText value="#{row[name]}" id="aot1"/>
                </af:column>
              </af:forEach>
            </af:table>
          </af:form>
        </af:document>
    managed bean:
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    
    import java.util.Map;
    
    import org.apache.myfaces.trinidad.model.CollectionModel;
    import org.apache.myfaces.trinidad.model.SortableModel;
    
    
    public class MyBean {
        private SortableModel model;
        private List<String> columnNames;
    
        public MyBean() {
            System.out.println("Cntl in MyBean constructor :::");
            columnNames = new ArrayList<String>();
            columnNames.add("Col-1");
            columnNames.add("Col-2");
    //        generateColumnModel();
        }
    
        public void generateColumnModel() {
            this.model = new SortableModel(createRows(columnNames));
        }
    
        private static List<Map> createRows(List<String> columnNames) {
            int i = 0;
            List<Map> mapListforRows = new ArrayList<Map>();
            //for (String name : columnNames) {
                Map newRow = new HashMap();
                mapListforRows.add(newRow);
                for (String col : columnNames) {
                    newRow.put(col, "data");
                }
           // }
            return mapListforRows;
        }
    
    
        public String add() {
            System.out.println("Cntl in add method :::");
    //        columnNames = new ArrayList<String>();
    //        columnNames.add("Col-1");
    //        columnNames.add("Col-2");
            generateColumnModel();
            return null;
        }
    
        public CollectionModel getCollectionModel() {
            return model;
        }
    
        public void setColumnNames(List<String> columnNames) {
            this.columnNames = columnNames;
        }
    
        public List<String> getColumnNames() {
            return columnNames;
        }
    
    }
    I hope this will help you to solve your use case

    ~Abhijit
    Abhijit Dutta
  • Shay Shmeltzer-Oracle
    Shay Shmeltzer-Oracle Director of Product Management for Oracle's Cloud Development Tools Posts: 16,873 Employee
    If you just need to show the table in read only mode you can use the dynamic components:
    http://blogs.oracle.com/shay/2010/10/adf_faces_dynamic_tags_-fora.html
This discussion has been closed.