Java Reference
In-Depth Information
All that needs to be done now is to make the view (InsEmpInfo) invoke the model (i.e., the Employee class's insert
function). As mentioned, a new tag call insEmp will be created to perform the insert function. The tag will be added to
InsEmpInfo such that the insEmp tag is executed after the button is clicked.
Tutorial: Modifying the View
Let's make the necessary changes:
1.
In Java Resources/src/c11, create a new Java class called InsertEmp with a super class of
TagSupport and no method stubs.
2.
In InsertEmp, add the following statements to define an Employee class variable called emp.
private Employee emp;
3.
In InsertEmp, click Source, then Override/Implement Methods. . .
4.
At the Override/Implement Methods window, click on the doStartTag() checkbox to select it,
and then click the OK button.
5.
Before the return statement in doStartTag, add the following statement:
emp = (Employee) pageContext.getRequest().getAttribute("EmpBean");
This statement retrieves EmpBean using the PageContext object. Unfortunately, the bean is returned as a type of
Object . So, the Object must be cast as an Employee before it can be assigned to the variable emp.
6.
After the above statement, add the following statement that invokes the insert function.
emp.doInsert();
7.
Save the file
8.
In TNT.tld, add the following XML to define the new insEmp tag and associate the tag with
the tag handler class InsertEmp:
<tag>
<name>insEmp</name>
<tagclass>c11.InsertEmp</tagclass>
</tag>
9.
Save TNT.tld.
In InsEmpInfo.jsp, delete the choose , when , and forward tags.
10.
This can be done by deleting the source code in the Source view or by selecting the choose icon in Page Designer
(see Figure 11-13 ) and pressing the Delete key.
 
Search WWH ::




Custom Search