Here is a scenario where we need to edit the table records and update them, here table is based on Bean DataControl. so in this article, I'm trying to explain how can we edit the table records using Bean DataControl.
You can download the sample workspace from here
[Runs with Oracle JDeveloper 11.1.2.0.0 (11g R2) + HR Schema]
Implementation Steps
Create Fusion Web Application, create the DeptBean.java, EmpBean.java and GenericBean.java classes in model project and paste the below code.
Open DeptBean.java and paste the below code.
Open EmpBean.java and paste the code.
Open GenericBean.java and paste the below method code.
Now right click on GenericBean.java file and generate data control. Open the DataControl.dcx file in application navigator and select the GenericBean. Go to the GenericBean property inspector and set SupportsTransactions as true.
In the ViewController create index.jspx page, create adf bounded task flow "BeanDCEditable-btf" and from component palette drag and drop two view BrowsePage.jsff, EditPage,jsff. Now draw a navigation case from BrowsePage to EditPage and change outcome to "edit" and draw a navigation case from EditPage to BrowsePage and change outcome to "browse".
Open BrowsePage.jsff, from data control palette drop populateBean->DeptBean->empsCollection->Master-Details as ADF Master Form, Detail table and RowSelection as Single. From component palette drop a button and Action as "Edit".
Open EditPage.jsff, from data control palette drop populateBean->DeptBean->empsCollection->Form as ADF Form and include Submit button with Action as "browse".
Open the index.jspx page, drop the BeanDCEditable-btf as region and run the index.jspx page. Once the page load select the any row in the empsCollection table, change the EmpName value and submit the page. Now validate that the changes made in the editPage are visible in browsePage as show below image.
You can download the sample workspace from here
[Runs with Oracle JDeveloper 11.1.2.0.0 (11g R2) + HR Schema]
Implementation Steps
Create Fusion Web Application, create the DeptBean.java, EmpBean.java and GenericBean.java classes in model project and paste the below code.
Open DeptBean.java and paste the below code.
public class DeptBean {
private String deptNo;
private String deptName;
private Collection empsCollection = new ArrayList();
public DeptBean() {
super();
}
public DeptBean(String dno, String dname, Collection emps) {
this.deptNo = dno;
this.deptName = dname;
this.empsCollection = emps;
}
public void setDeptNo(String deptNo) {
this.deptNo = deptNo;
}
public String getDeptNo() {
return deptNo;
}
public void setDeptName(String deptName) {
this.deptName = deptName;
}
public String getDeptName() {
return deptName;
}
public void setEmpsCollection(Collection empsCollection) {
this.empsCollection = empsCollection;
}
public Collection getEmpsCollection() {
return empsCollection;
}
}
Open EmpBean.java and paste the code.
public class EmpBean {
private String deptNo;
private String empId;
private String empName;
public EmpBean() {
super();
}
public EmpBean(String id, String name, String dno) {
this.deptNo = dno;
this.empId = id;
this.empName = name;
}
public void setDeptNo(String deptNo) {
this.deptNo = deptNo;
}
public String getDeptNo() {
return deptNo;
}
public void setEmpId(String empId) {
this.empId = empId;
}
public String getEmpId() {
return empId;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public String getEmpName() {
return empName;
}
}
Open GenericBean.java and paste the below method code.
/**
* Creating a List which has 10 departments
* and 5 employees in each department.
* @return DeptBean list
*/
public List populateBean() {
List deptList = new ArrayList();
int noOfDepts = 1;
while (noOfDepts < 11) {
String deptNo = "" + noOfDepts;
String deptName = "DeptName_" + noOfDepts;
List empList = new ArrayList();
int noOfEmps = 1;
while (noOfEmps < 6) {
String empId = deptNo + noOfEmps;
String empName = "EmpName_" + deptName + "_" + empId;
EmpBean emp = new EmpBean(empId, empName, deptNo);
empList.add(emp);
noOfEmps++;
}
DeptBean dept = new DeptBean(deptNo, deptName, empList);
deptList.add(dept);
noOfDepts++;
}
return deptList;
}
Now right click on GenericBean.java file and generate data control. Open the DataControl.dcx file in application navigator and select the GenericBean. Go to the GenericBean property inspector and set SupportsTransactions as true.
In the ViewController create index.jspx page, create adf bounded task flow "BeanDCEditable-btf" and from component palette drag and drop two view BrowsePage.jsff, EditPage,jsff. Now draw a navigation case from BrowsePage to EditPage and change outcome to "edit" and draw a navigation case from EditPage to BrowsePage and change outcome to "browse".
Open BrowsePage.jsff, from data control palette drop populateBean->DeptBean->empsCollection->Master-Details as ADF Master Form, Detail table and RowSelection as Single. From component palette drop a button and Action as "Edit".
Open EditPage.jsff, from data control palette drop populateBean->DeptBean->empsCollection->Form as ADF Form and include Submit button with Action as "browse".
Open the index.jspx page, drop the BeanDCEditable-btf as region and run the index.jspx page. Once the page load select the any row in the empsCollection table, change the EmpName value and submit the page. Now validate that the changes made in the editPage are visible in browsePage as show below image.
Hi, do you know if it is possible to get the table values and store them into an ArrayList?
ReplyDeleteI need it to sort the table with a custom criterion.
thnaks