8.2 Tag Libraries Included with Struts

The Struts framework provides a fairly rich set of framework components. It also includes a set of tag libraries that are designed to interact intimately with the rest of the framework. The custom tags provided by the Struts framework are grouped into four distinct libraries:

  • HTML

  • Bean

  • Logic

  • Tiles

There also is a fifth library, called the Nested tag library, that we'll talk about separately later in this chapter.

Earlier versions of the Struts framework contained a tag library called Form. It was replaced with the HTML tag library several versions ago, but form tags still sometimes show up in the documentation or example applications.

The tags within a particular library perform similar or related functions. For example, the tags within the HTML tag library are used to render HTML presentation components inside HTML forms. There's a tag to generate a checkbox, another for a button, and yet another to generate a hyperlink.

8.2.1 Using Tag Libraries with Struts Applications

There's nothing special about using the Struts tags they are like any other JSP custom tags. You must include the TLD declarations for each tag library you use in every page in which you need to use them. If you need to use the HTML and Logic tag libraries in a JSP page, for example, insert the following two lines at the top of the JSP page:

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

Once these lines are included and your web application deployment descriptor contains the necessary taglib elements, you can use the HTML and Logic tags within your JSP page. Continuing with the previous example, you need to add the following lines to your web.xml file:

<taglib>   <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>   <taglib-location>/WEB-INF/struts-html.tld</taglib-location> </taglib> <taglib>   <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>   <taglib-location>/WEB-INF/struts-logic.tld</taglib-location> </taglib>

Based on the snippets above, you would also need to make sure that the TLD files that are included with Struts are placed in the WEB-INF directory. This is not the only location that they can reside, but is the most common.

For more information on configuring the deployment descriptor for the web application, see "Configuring the web.xml File for Struts" in Chapter 4.

Programming Jakarta Struts
Programming Jakarta Struts, 2nd Edition
ISBN: 0596006519
EAN: 2147483647
Year: 2003
Pages: 180

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net