Now that there are fields for the data on the page, you need
to add the code that retrieves the data from the database. Recall
from the previous lesson that you added a link to pass the customer
ID number in a parameter named CID. In these steps,
you will set up the handler for new web page to accept this parameter
and retrieve the appropriate record from the database to be displayed
on the page.
- Right-click anywhere in the free-form area of the updatecustomer.jsp
file.
- From the popup menu, click Edit Page Code. The updatecustomer.egl file opens in the editor.
- As in the previous JSF Handler you edited, you need to
add a record to store the success or failure code of the SQL call.
Immediately after the line customer Customer;, add
the following code, exactly as written:
status StatusRec;
The next step in adding the data to the page is to configure
the JSF handler to accept the CID parameter that
the link will pass to it.
- Change the line function onPreRender() to
the following code, exactly as written:
function onPreRender(CID INT)
Now the JSF handler is configured to accept an integer
parameter named CID.
- On a blank line immediately after the function
onPreRender(CID INT), add this code, exactly as written:
customer.customerId = CID;
Now you have
assigned the ID number to the customer record. The next step is to
retrieve the record with this ID number from the database
- On the next line, add this code, exactly as written. You may want to use the code completion feature you learned
about in Lesson 6: Add data to the page.
CustomerLib.GetCustomer(customer, status);
The GetCustomer function
works just like the GetCustomerAll function you used
previously, but the GetCustomer function retrieves
one record, while the GetCustomerAll function retrieves
an array of records. Now the customer record contains
the record with the ID passed to this JSF handler.The new function
looks like this:
function onPreRender(CID INT)
customer.CustomerId = CID;
CustomerLib.GetCustomer(customer, status);
end
- Optimize imports and save the file.
The JSF handler looks like this:
Now when you click
a link on the allcustomers.jsp page, the updatecustomer.jsp page loads
with details about that customer's record. Right now, you can change
the information in the fields on the web page, but there is no function
to send those updates to the database. In the next section, you will
use the UpdateCustomer function to make those updates
to the database.