Jake Kronika is a web designer and developer

Jake Kronika is a web designer and developer with over fifteen years of experience, and brings to this book a strong background in front-end development with JavaScript and jQuery, as well as significant training in server-side languages and frameworks. Having earned a Bachelors of Science degree in Computer Science from Illinois Wesleyan University in 2005, with a minor in Business Administration, he went on to become Senior User Interface (UI) Specialist for Imaginary Landscape, LLC, a small web development firm in the Ravenswood neighborhood on the north side of Chicago. In this role, the foundations of his strengths in Cascading Style Sheets (CSS) and JavaScript (JS) were honed and finely tuned. From there, Jake went on to work for the Sun-Times News Group, owner of the Chicago Sun-Times and numerous suburban newspapers in Chicagoland. It was in this role that he was initially exposed and rapidly gained expert skills with the jQuery framework for JS. Following intermediate positions as Technology Consultant with Objective Arts, Inc, and as UI Prototyper for JP Morgan Chase, Jake moved across the contiguous United States to Seattle, WA, where he assumed his current role of Senior UI Software Engineer with the Cobalt Group, a marketing division of ADP’s Dealer Services. Since 1999, he has also operated Gridline Design & Development (so named in 2009), a sole proprietorship for web design, development, and administration. Jake has also reviewed Django JavaScript Integration: AJAX and jQuery, a Packt Publishing text authored by Jonathan Howard and published in January of 2011.

About the Reviewers Vijay Joshi is a programmer

About the Reviewers Vijay Joshi is a programmer with over six years of experience on various platforms. He discovered his passion for open source four years back when he started playing with PHP on a hobby project after completing his Masters in Computer Applications. Vijay is now a freelance web developer, independent consultant for a few selected companies, and a blogger at http://vijayjoshi.org. He specializes in developing custom web applications, mashups, creating apps using PHP frameworks, and enhancing existing web apps using PHP and front-end libraries like jQuery, jQUI, and so on. Vijay is also the author of PHP jQuery Cookbook and a technical reviewer of PHP AJAX Cookbook both of which have been published by Packt. Outside of work, he enjoys reading, trekking, and sometimes gets obsessed with fitness.

About the Author Dan Wellman is an author

About the Author Dan Wellman is an author and web developer based on the South Coast of the UK. By day he works alongside some of the most talented people he has had the pleasure of calling colleagues, for a small, yet accomplished digital agency called Design Haus. By night he writes books and tutorials on a range of front-end topics. He is hopelessly addicted to jQuery. His life is enriched by his four wonderful children, a beautiful wife, and a close circle of family and friends. This is his sixth book. Thanks to everyone who was involved in the book, the editorial team at Packt, the reviewers, and the hugely talented team responsible for jQuery UI. Props to my friends Steev Bishop, Andrew Herman, Dan Goodall, Aaron Matheson, James Zabiela, Jon Adams, Eamon O’Donoghue, and Dan Isles.

Credits Author Proofreader Dan Wellman Aaron Nash Reviewers

Credits Author Proofreader Dan Wellman Aaron Nash Reviewers Indexers Vijay Joshi Tejal Daruwale Jake Kronika Hemangini Bari Acquisition Editor Graphics Sarah Cullington Nilesh Mohite Development Editor Production Coordinators Hithesh Uchil Aparna Bhagat Nilesh Mohite Technical Editors Lubna Shaikh Cover Work Merwine Machado Aparna Bhagat Nilesh Mohite Project Coordinator Michelle Quadros

jQuery UI 1.8 The User Interface Library for

jQuery UI 1.8 The User Interface Library for jQuery Copyright 2011 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: August 2011 Production Reference: 1120811 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-849516-52-5 www.packtpub.com Cover Image by Karl Swedberg (karl@englishrules.com)

Generalized iterating tags protected void clearProperties() { elements

Generalized iterating tags protected void clearProperties() { elements = null; c super.clearProperties(); } } class IteratorIterationSupport implements IterationSupport { d Iterator i = null; IteratorIterationSupport(Iterator i) { this.i = i; } public boolean hasNext() throws JspException { return i.hasNext(); } public Object getNext() throws JspException { return i.next(); } } b Parsing the list specification string and making an IterationSupport out of it. C Clearing the additional tag property. D Implementing an IterationSupport class that uses a Java Iterator object. The new ForeachTag has most of its code implementing its tag-specific functionality, that is, dealing with an Iterator of Strings. Also of note in our implementation is the additional IteratorIterationSupport class we created, which is simply an implementation of the generic IterationSupport that works on the java.util.Iterator interface. We can imagine a similar class that works on Arrays and even another for Enumerations (or perhaps one that handles all?). The IteratorIterationSupport class is not, of course, unique to ForeachTag and we will be able to reuse it many times in other specialized tags. We now have a way to easily create iteration tags that iterate on all sorts of objects. We ll flex the power of this infrastructure in the next section in creating a tag that is capable of iterating on just about anything.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services

Generalized iterating tags // User probably disconnected …

CHAPTER 10 Iterating with tags D Override if you have additional attributes in the specialized tag (you probably do). E Override if you have additional service state in the specialized tag. Listing 10.5 shows that the general structure of IterationTagSupport is very similar to the one presented in SimpleForeachTag. The tag is merely a generic iteration infrastructure with several methods to override as explaned in the annotations. Note also that IterationTagSupport extends our now familiar ExBodyTagSupport, and therefore inherits its functionality. An improved ForeachTag which uses IterationTagSupport We ve mentioned several times the concept of a specialized tag, by which we infer a tag that uses our generic interface and class for a specific iterator and object type. Let s now look at one such specialized tag, ForeachTag, which uses IterationTag- Support to support an Iterator containing a list of Strings (see listing 10.6). Listing 10.6 Source code for the ForeachTag handler class package book.iteration; import java.util.StringTokenizer; import java.util.LinkedList; import java.util.Iterator; import java.util.List; import book.util.LocalStrings; import book.util.ExBodyTagSupport; import javax.servlet.jsp.JspException; public class ForeachTag extends IterationTagSupport { static LocalStrings ls = LocalStrings.getLocalStrings(ForeachTag.class); protected String elements = null; public void setElements(String elements) { this.elements = elements; } protected void fetchIterationSupport() throws JspException { List l = new LinkedList(); b StringTokenizer st = new StringTokenizer(elements, “,”); while(st.hasMoreTokens()) { l.add(st.nextToken()); } elementsList = new IteratorIterationSupport(l.iterator()); }

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services

Generalized iterating tags // User probably disconnected …

Generalized iterating tags // User probably disconnected … // Log and throw a JspTagException } if(elementsList.hasNext()) { exportVariables(); return EVAL_BODY_TAG; } return SKIP_BODY; } protected abstract void fetchIterationSupport() b throws JspException; protected void exportVariables() c throws JspException { pageContext.setAttribute(id, elementsList.getNext()); } protected void clearProperties() d { id = null; super.clearProperties(); } protected void clearServiceState() e { elementsList = null; } } B First override point. The specialized tag must implement this method to create and set an IterationSupport object The first method that tags can and must override is fetchIterationSupport(). This abstract method is the location wherein the overriding tag should implement the creating and setting of the IterationSupport object and any specialized iteration tag must provide such objects to make the generic infrastructure work. If problems rise within fetchIterationSupport(), it can throw a JspException that the generic implementation will pass to the JSP runtime. C Second override point. The specialized tag may want to export additional objects The second method that can be overridden is exportVariables(), which is where the generic iteration tag exports the iterator (based in the id attribute). An overriding tag may override this method to add more variables. For example, a certain tag iterates a hash table and wants to export both the key to the table and the value itself. In this case you would like to add the exportation of the value variable along with the default iterator.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services

Generalized iterating tags Listing 10.4 Source code for

CHAPTER 10 Iterating with tags is custom built to handle a particular iterator type and a particular type of object in that iterator. Export a different set of JSP variables. Whenever IterationTagSupport wants to export its iterator value, it should call yet another method that can be overridden by the specialized tag (but the default implementation of the variable exportation method should export only a single iterator). IterationTagSupport s implementation IterationTagSupport was created with a few methods that may be overridden by specialized iteration tags. Listing 10.5 Source code for the generic iteration tag handler package book.iteration; import book.util.LocalStrings; import book.util.ExBodyTagSupport; import javax.servlet.jsp.JspException; public abstract class IterationTagSupport extends ExBodyTagSupport { static LocalStrings ls = LocalStrings.getLocalStrings(IterationTagSupport.class); IterationSupport elementsList = null; public int doStartTag() throws JspException { fetchIterationSupport(); if(elementsList.hasNext()) { return EVAL_BODY_TAG; } return SKIP_BODY; } public void doInitBody() throws JspException { exportVariables(); } public int doAfterBody() throws JspException { try { getBodyContent().writeOut(getPreviousOut()); getBodyContent().clear(); } catch(java.io.IOException ioe) {

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services