Chapter 6: Struts Tag Libraries


In this chapter:

  1. You will learn about frequently used Html, Bean and Logic tags

  2. We will customize these Html tags ‚ base, text, checkbox, errors & image

  3. You will learn about JSTL and Expression Language

  4. You will understand how to use Struts-EL Tags and which of the Struts tags should be replaced with JSTL and Struts-EL

  5. You will see how various Struts tags, their derivatives and other related tags can work together to create multi-page lists and editable lists.

Custom Tags were introduced in JSP 1.1 specification. They are elegant replacement for the scriptlets. Without the custom tags, the ‚“ edge of the system ‚½ where the decisions in presentation logic based on middle tier models would be exposed to the JSP page author as Java scriptlets. While not only causing confusions and headaches to the page author, scriptlets also required the involvement of the Java developer in the page authoring. Custom Tags changed all that. The application developer now provides the custom tags written as a Java class with a pre-defined structure and hierarchy. The page author independently designs the pages and decides on the contents using the custom tags and their formatting using general HTML and CSS.

Struts ships with these Tag libraries ‚ Html, Bean, Logic, Template, Nested, Tiles. We will deal with the first three tag libraries in this chapter. The TLD file for each of these libraries is included in the Struts distribution. For instance, the Html Tags are defined in struts-html.tld . The Bean tags are defined in struts-bean.tld and so on. These tags are like any other custom tags. You have to include the TLD declarations in the web.xml and also the JSP. For e.g., you have to add the following lines in the web.xml to use the Html Tag library:

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

and the following line in the JSP:

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

Excellent documentation is available with the Struts distribution for each of the custom tags and their attributes. It will be merely a repetition of going over each of those attributes and tags here. Instead we will gloss over the categories and characteristics of the Struts Tags and more importantly cover tags that need to be customized for use in serious applications.

Here is how to access the tag documentation in Struts distribution:

Deploy the struts-documentation.war from Struts webapps in Tomcat. Use the URL http://localhost:8080/struts-documentation/ to access the documentation in the browser. Click on the link named ‚“ Learning ‚½ on the left hand side. Click on ‚“ User and Developer Guides ‚½ on the resulting page. The page that you see at this point is loaded with information and links including links for Struts tag documentation. The direct link for Struts HTML Tag documentation is: http://localhost:8080/struts-documentation/userGuide/dev_html.html. The direct link for Struts Bean Tag documentation is: http://localhost:8080/struts-documentation/userGuide/dev_bean.html.




Struts Survival Guide. Basics to Best Practices
Struts Survival Guide: Basics to Best Practices (J2ee Survival Series)
ISBN: 0974848808
EAN: 2147483647
Year: 2004
Pages: 96

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