This task is the second of four in a demonstration on how to create
a multi-page SDO application. In this task you create a configure the master
page to work with multiple-use SDO and the detail page. It assumes you have
completed:
- From Page Data view, drag a relational record onto a JSP that you want
to use as a master page. If you are working with the DB2® V8.2 SAMPLE database and have completed
the previous tasks, open the updateDepartment.jsp.
- Select Updating an existing Record, then click Finish to
generate the form on the master page.
- Save the JSP.
- Right click on the JSP and select Edit Page Code.
By default, a Java™ file is shown containing server code for the JSP.
If you are working with the DB2 V8.2 SAMPLE database and have completed the previous
task, verify that methods getDepartment()and getDepartmentMediator() are
created.
- Modify the get<SDO-Name>() method with code that
will update the appropriate database table. For example, you could replace
the getDepartment() method with the following:
public DataObject getDepartment() {
if (department == null) {
if(!getSessionScope().containsKey("department")){
doDepartmentFetchAction();
getSessionScope().put("department", department);
} else
department = (DataObject) getSessionScope().get("department");
}
return department;
}
- Save and close the Java file.
- On the master page, for example, updateDepartment.jsp,
drag a Link - Command next to the Delete button.
- Click on link label.
- In the Properties view, click h:outputText beneath
h:commandLink and change the Value field to a name appropriate for the action,
for example, Add Employee, then press Enter.
- Select h:commandLink, then click the Quick Edit view icon next to "Click
to code the action this link performs."
- In the left column, click Command.
- Right-click in the script editing area and select .
The Create SubRecord window opens:
- Select the appropriate record or record list, then select the node representing
the table that should be updated, for example, DEPARTMENT_EMPLOYEE (EMPLOYEE).
- Enter a variable name, for example, employee.
- Select Session from the Variable Scope list, then
click OK. If you are working with the DB2 V8.2 SAMPLE
database, verify that the following code is added to the Quick Edit view:
//actionBegin: wdo.createsub.record
DataObject employeeListParent = getRootDataObject(getDepartment()).getDataObject("DEPARTMENT[1]");
DataObject employeeList = getRootDataObject(getDepartment()).createDataObject(" EMPLOYEE");
employeeListParent.getList("DEPARTMENT_EMPLOYEE").add(employeeList);
getSessionScope().put("employeeList", employeeList);
//actionEnd: wdo.createsub.record
- Return to the h:commandLink tab of the Properties view, then click Add
rule.
- Add a navigation rule so that the Link - Command action goes to another
JSP, for example createEmployee.jsp.
- Save the JSP.