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.
Post a Comment