advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement



Title: JSP Tag Libraries
ISBN: 193011009X
US Price: $35.96
Publication Date: May 2001
Pages: 656
© 2001 Manning Publications Co.

Reviews : Java Books :
JSP Tag Libraries : Chapter 10: Iterating with Tags

10.2 Generalized iterating tags

In perusing the implementation of SimpleForeachTag it appears that most of the work done by the tag is not unique to it. In fact, other than the creation of the Iterator object in parseElements() all the other code was generic. True, some tags will not want to expose an iterator, and others may want to expose more than a single iterator as a scripting variable (for some other tag-specific purpose), but these tags are not representative of the majority. In most cases, tags will differ only in the objects they iterate (some will iterate over an Enumeration, others on Array, etc.) but the general structure will stay the same; a single iterator scripting variable will be exposed and updated for each element.

Based on this general iterating structure, we'll build:

  • A generic iteration interface that lets the tag developer specify how to iterate over some set of objects. .
  • A basic iterator tag that takes a generic iteration object (Enumeration, Array, etc.) and iterates on it.

Creating these two, generic components will then streamline the creation of various iteration tags. These specialized iteration tags will be custom-built, based on the type of Java object to be contained in the iterator, and the iterator type in which these objects are to be contained. For example, our SimpleForeachTag had an iterator type of java.util.Iterator, and contained in that iterator was a list of Strings. We are now going to build these two components (the class and interface) and modify SimpleForeachTag to use this new, more generic infrastructure.

10.2.1 A generic iteration interface

Before looking into the new ForeachTag, let's study the generic iteration infra-structure on which it is constructed, starting with the generic iteration interface as seen in listing 10.4.

Listing 10. 4 Source code for the generic iteration interface

package book.iteration; 

import javax.servlet.jsp.JspException; 

public interface IterationSupport { 
	public boolean hasNext() 
		throws JspException; 

	public Object getNext() 
		throws JspException; 
}

Why do we need another iteration/ enumeration interface, as Java already offers plenty. You may also wonder, why a JspException is thrown from the methods hasNext() and getNext(). Shouldn't a generic interface remove JSP related ties? We do this because we want to provide better JSP integration. Let's explore our motivation for this integration.

NOTE We could consider the option of defining a new exception type (such as IterationException) that the iteration support methods could throw; but why should we? This code is written for the JSP tags, and we are not going to reuse it. In 99 percent of all cases, you are going to throw a JspException as a result of the error. Based on this argument, we've rejected the new exception type idea, and continue to use JspException as our error-reporting vehicle.

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Microsoft Visual Studio 2010 Showcase
 Avaya Developer Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 39
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Windows 7: From Beta to Final Code in One Year
Google Shows Off Chrome OS, Releases Source
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?
Fedora 12 Takes Aim at Linux Networking
Top Supercomputer Nearly Doubles in Speed
Fedora 12 Linux Tackles Virtualization
Apple Gives iPhone Developers App Status Tracker
Novell Sets OpenSUSE 11.2 Free

Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Exploring HTML 5's Audio/Video Multimedia Support
Overriding Virtual Functions? Use C++0x Attributes to Avoid Bugs.
Understanding the Cloud Computing Security Vulnerabilities
Cisco and IBM Target a Greener World
Upgrade to Visual Studio 2010 with the Ultimate Offer

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs