Using the Logic Tag Library

 < Day Day Up > 



To use the Logic Tag Library in a Struts application, you need to include the following snippet in your Web Archive (.war) deployment descriptor, web.xml:

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

Recall from the overview of the web.xml file in Chapter 2 that the <taglib-uri> tag is used to declare the URI (or alias) that will be referenced in each of your JSPs with a taglib directive. The <taglib-location> tag is used to declare the actual location of the Tag Library Descriptor (.tld) file in your Web Archive.

The following snippet illustrates how your JSPs will declare their use of the Logic Tag Library with a JSP taglib directive:

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

Notice that the uri attribute specified here is the same as that declared with the <taglib-uri> tag in the web.xml file. Also, notice that the prefix attribute is set to “logic”. This attribute can be set to whatever you want; however, “logic” is the accepted default for the Logic Library. The prefix attribute declares the prefix that each tag must have when it is used in the JSP, as shown here:

<logic:present name="searchForm" property="results">

Because “logic” was defined as the prefix, the present tag was used as shown. However, if you chose to use a prefix of “strutslgc”, the tag would be used the following way:

<strutslgc:present name="searchForm" property="results">



 < Day Day Up > 



Struts. The Complete Reference
Struts: The Complete Reference, 2nd Edition
ISBN: 0072263865
EAN: 2147483647
Year: 2003
Pages: 134
Authors: James Holmes

Similar book on Amazon

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