Java Reference
In-Depth Information
<jsp:setProperty name="EmpBean" property="empState" param="stateTF" />
<jsp:setProperty name="EmpBean" property="empNum" param="empNumTF" />
<jsp:setProperty name="EmpBean" property="empName" param="empNameTF" />
<jsp:setProperty name="EmpBean" property="empZip" param="zipTF" />
<jsp:setProperty name="EmpBean" property="payRate" param="hPRTF" />
<jsp:setProperty name="EmpBean" property="empCity" param="cityTF" />
</jsp:useBean>
We will do this by creating:
A tag handler class called CrtEmpBean that is a subclass of
TagSupport . CrtEmpBean will
perform the same functions that the bean tags did (i.e., create and populate an Employee
bean). CrtEmpBean will use the EmpExtractor class to create the Employee object and then
define the Employee object as a Java bean with a scope of request.
A folder called
tls (tag libraries) in WEB-INF.
Within tls, a tag library file called TNT.tld with an entry to associate the custom tag getEmp
and the tag handler class CrtEmpBean
An entry in the Web Deployment Descriptor to define the URI
http://www.tnt.com/taglib and tie it to /WEB-INF/tls/TNT.tld
We will then use the custom tag in EnterEmpInfoJSP, by inserting:
A taglib directive that defines the prefix TNT and ties it to the URI
http://www.tnt.com/taglib
The custom tag with the prefix TNT (
<TNT:getEmp/>)
Tutorial: Creating a Custom Tag
Let's try it
1.
In the TutorialsWeb project, click on the WebContent folder to select it.
2.
Click File, New, Folder, specify c11 as the new folder name, and click the Finish button.
3.
From the WebContent/c9 folder, copy EnterEmpInfoJSP.jsp and EnterEmpInfoForm.html
into c11.
4.
In c11/EnterEmpInfoForm.html, ensure that the form action is specified as
EnterEmpInfoJSP.jsp. If it isn't, change it to EnterEmpInfoJSP.jsp.
5.
In TutorialsWeb/Java Resources/src, create a folder called c11.
6.
From c9java, copy Employee and EmpExtractor to c11.
7.
In src/c11, create a Java class called CrtEmpBean with a super class of TagSupport and no
method stubs.
The following source code will be inserted in CrtEmpBean and displayed in Page Designer:
package c11;
import javax.servlet.jsp.tagext.TagSupport;
public class CrtEmpBean extends TagSupport {
}
 
Search WWH ::




Custom Search