8.5.3.2 Modify the FacultyProcess Page to Handle Faculty Data Updating
Double-click on the FacultyProcess.jsp page in the Projects window and perform the fol-lowing modifications to this page to use the Java bean FacultyUpdateDeleteBean.java to perform the faculty record update actions:
1) Move the cursor to just under the line else if (request.getParameter(“Up date”)!= null), then open the Palette window by going to Window > IDE Tools > Palette. In the opened Palette window, browse to the JSP tab, drag the Use Bean icon and place it at the cursor location that is just under the else if code line, as mentioned previously.
2) In the opened Insert Use Bean dialog, enter UpdateFaculty in the ID field and
JavaWebOrcleSelectPackage.FacultyUpdateDeleteBean in the Class filed. Select session from the Scope combo box, and then click on the OK button. A JSP directive that contains the bean id, bean scope and class is added to this block.
3) Add a JSP directive to the Java bean class FacultyUpdateDeleteBean.java:
4) Add the opening and ending JSP directives <% to enclose those two JSP directives we added previously.
The code related to steps 1~4 is shown in the top on Figure 8.91. Add the code shown in steps A~G in Figure 8.91 into this block. Let’s have a closer look at this code to see how it works.
A. A local integer variable, update, is created and used to hold the run result of executing the UpdateFaculty() method in the Java bean class FacultyUpdateDeleteBean with the bean id of UpdateFaculty.
B. Eight getParameter() methods are used to pick up eight pieces of updated faculty information stored in the eight fields in the Faculty.jsp page. The eight collected pieces of new faculty information are assigned to eight local String variables.
FIGURE 8.91 The modified code for the Update block.
C. If the user forgot to select an updated faculty image with this data update, the program is directed to return to the Faculty.jsp page to enable the user to do that selection without any update action being performed. The function of this data update action is that the user must select an updated faculty image to continue the data update. The same faculty image should be selected if the user does not want to update that faculty image.
D. A new String array, upf[], is created, and it is used to hold eight pieces of updated faculty information stored in the eight local String variables.
E. The UpdateFaculty() method in our Java bean is executed to update a faculty record with these eight pieces of faculty information in the Faculty Table. The eight pieces of updated faculty information are stored in the String array upf[] that works as the argu-ment for this method. The run result of this method is returned and assigned to the local integer variable update.
F. If the run result is 0, it means that no record has been updated in the Faculty Table, and this data update action fails. In that case, we need to re-display the Faculty.jsp page to enable users to re-update that faculty record.
G. Otherwise, if the run result is non-zero, it means that at least one faculty record has been updated in the Faculty Table. We can clean up all seven fields that contain seven pieces of updated faculty information in the Faculty.jsp page to enable users to either to test the update or update another faculty record.
H. We need to re-display the Faculty.jsp page to enable users to perform the next action.
Prior to building and running this Web application, make sure that the faculty image to be selected and updated, in this case, David.jpg, has been stored in a desired default project folder, in this case C:\Class DB Projects\Chapter 8\JavaWebOracleUpdateDelete\web\ FImages. Of course, you can select any other folder you like to store these faculty images.