Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.

Thursday, October 4, 2007

Creating List Based ADF Table for data capturing

Sometimes, there is a requirement to capture a set of user inputs which is needed for some temporary computations. For example say details of some employees is required and it is not based on any database table. In that case, many a time creating a temporary table in the database is not always desired. To avoid that you can base your ADF table component on a java.util.List object (other objects too possible in the similar manner).

STEP By STEP: Find Live Demo Here
  1. Say we have to create a table component to capture emp code, emp name and dept of n number of employees. To do this, just drop a ADF table component on your jspx(or jsp ) page. and create three columns. Give headers as EmpCode, EmpName, Dept. for values property type as: #{row.empCode}, #{row.empName} and #{row.dept}, respectively. Also change the column types from outputText to inputText.
  2. Now, you need a List object to bind this ADF table. Ofcourse, this List will be containing items as another java objects to hold value for each of the table column. Go to the table properties in the property inspector and choose value property. Click on the button on the right side. It will ask for the managed bean name. Give bean name as DemoBean. package say vik.demo.ui.bean, bean scoipe as session, and property name as entryList.
  3. This will create a manged bean named DemoBean with default constructor. Now declare a private class member as Private List entryList. Now right click on it and choose generate accessors.
  4. Now, you will need a another java class which can initialize the rows of table and can populate the entryList created above. For this create a new java class and declare three members as public String empCode; public String empName; public String dept; Finally, right click and choose generate accessors.
  5. Now, come back to DemoBean.java and in the constructor write code as: if(entryList == null){ entryList = new ArrayList(); }.
  6. Go to your jspx file and click on the table component created in step 1 in the structure window. In the var property enter row.
  7. Now, you need a button to add blank rows into the table. For this drag and drop a button to the table header. Name it as Add Row. Click on the button right side of actionListener property. Choose manage bean name as DemoBean. and give a method name say OnClickAddRowBtn.
  8. Go to DemoBean.java and in the OnClickAddRowBtn add following code: EmpBean e;
    e = new EmpBean();
    e.setEmpCode("");
    e.setEmpName("");
    e.setDept("");
    list.add(e);
    return;
  9. Congratulations!!!! You are done.

8 comments:

ADF Developer said...

Thanks for the great post :)

But now i have a question "How to get the values of the selected row in such ADF table which bounded to arraylist?" as my ADF table row selection property is set to "single"

Tripuresh Pandey said...

Hi,

How can we add a af:query panel based on such adf tables which are dependent on list data from bean?

Tripuresh Pandey said...

hi,

how can we create a af:query panel based on such tables?

Unknown said...

Tripuresh depending on your overall requirements I think today i can suggest better solution for the same rather creating a List based af:table if you need a query panel as well.

Creating a transient VO would be a much better solution in your case. The VO can be populated programmatically like List by overriding some of the methods in VOImpl and for the query panel you may create a vc on this VO. Hope this helps

Tripuresh Pandey said...

Hi Vivek,

Thanks for the quick response.

Actually if i modify the existing design it will be lots of rework on existing code.
So, is there any way to create a query panel customised to this sort of table.

Unknown said...

Unfortunately, dont see a way out to get a query panel based on a list based table. If you have already got into search panel sort of requirements then better to do that lot of work now rather later. I am afraid your trouble will increase many folds with current design to accommodate new requirements.

And yes will advise you to post on jdeveloper forums as a last resort.

Tripuresh Pandey said...

Ok , i will analyze the rework and make necessary changes.
Thanks a lot vivek

Unknown said...

Most welcome !