Abdul
Abdul

Reputation: 1208

How to create a table in adf with variable no of columns

Hello I am developing a web application using ADF (jdeve11.1.2.4). I know how to populate a table programatically from this post Programmatic ADF Table

But in the above post the no of columns are fixed (It is bean structure). But I cannot use the above post. Because I need to create a table with 'n' no-of columns. Means Columns are not fixed. Some times the columns may be 4 or some times the columns may be 7 and what ever it may be. Suppose I have two sqls and both contains differnt no of columns.

Ex: (suppose student is a table)
   select id from student
   select id,name from student

so in the above two sqls no of columns are diffent. I need to show the resul set of the above queries in a tablular format.

Please help me how I can achieve this.

Thanks in advance.

Upvotes: 0

Views: 3390

Answers (2)

Joe
Joe

Reputation: 3347

I wonder if declarative mode view objects would help? Blog here. So the query is not built until the UI is gen'd. You could dynamically generate the table and insert columns and then bind to the VO.

Upvotes: 2

Florin Marcus
Florin Marcus

Reputation: 1657

That's quite complex to do and it may require some extra study:

  1. create a programatic view object by passing your sql statement using:

    ApplicationModuleImpl.createViewObjectFromQueryStmt(java.lang.String voName,java.lang.String query)

  2. try to construct af:columns in a loop:

<af:table value="#{bindings.EmployeesView1.collectionModel}" .. id="t1">
  <af:iterator id="i1" value="#{bindings.EmployeesView1.attributesModel.attributes}" var="column" rows="0">
    <af:column headerText="#{column.label}" id="c1">
      <af:outputText id="d1" attributeModel="#{column}" value="#{row.bindings[column.name].inputValue}" />
    </af:column>
  </af:iterator>
</af:table>

Upvotes: 1

Related Questions