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)

CHAPTER 15 USING STRUTS, XDOCLET, AND OTHER

CHAPTER 15 USING STRUTS, XDOCLET, AND OTHER TOOLS 621 for messages as an application init parameter. We used this setting, as well as the nocache init parameter. In Struts 1.1, these settings have been deprecated and moved to a element in the struts-config.xml file. The following setting can be found in metadata/web/ struts-controller.xml: The nocachesetting tells the controller to add HTTP headers to prevent caching of content it s off by default. You can also specify a forwardPattern attribute, such as WEB-INF/pages/$M$P, where the $M variable indicates the module prefix and $P indicates the pathattribute of the selected element, although it isn t used here. The inputForward attribute allows you to use local or global forwards in the inputattribute of an action mapping. This is a very handy and much needed feature. Note More information on optional values and their meanings can be found online at http:// struts.apache.org/userGuide/configuration.html. The application s ResourceBundle is now specified in a element in struts-config.xml. If you re using XDoclet, you can place this in a struts-message-resources.xml file. In the struts-resume application, this file is located in the same location as the rest of the Struts configuration fragments: Since we keep this file (ApplicationResources.properties) directory under WEB-INF/ classes, there is no need to specify a package name. You can also specify alternate resource bundles for the application by adding a second element and specifying a key attribute: This can be useful if, for instance, you re building a product using Struts and you only want to expose a minimal amount of options that customers may change. To use this ResourceBundle with the tag, you only need to specify a bundleattribute that matches the key: Now that you ve seen how to set up modules for an application, let s see how to switch between them. For demonstration purposes, we ve added an upload module to struts-resume for uploading r sum s. This module doesn t demonstrate much more than file upload and module switching. It could be developed into a feature that allows for simple uploading of existing r sum s, but not much more than that. At the time of writing, there are two basic techniques to switching modules. The first involves using a forward (global or local) with a

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

CHAPTER 15 USING STRUTS, XDOCLET, AND OTHER

620 CHAPTER 15 USING STRUTS, XDOCLET, AND OTHER TOOLS Since the development of modules is very similar to developing a standard Struts application, we ll show you how to set them up, and we ve actually implemented an upload feature that uses them in the struts-resume application. The setup is rather simple, consisting of the following three steps: 1. Prepare a config file for your module. 2. Inform the controller of the module. 3. Use forwards or actions to switch to your new module. We won t detail the first step here, because this is the same as creating a new Struts application. You could probably use XDoclet to create your configuration files for the different modules, but you would have to coax your Ant webdoclet task to output struts-config.xml to different directories. Of course, the purpose of submodules is to make development and configuration easier, and XDoclet already does this for you! The second step involves adding a new init parameter to the ActionServlet s definition in the application s deployment descriptor, web.xml. In the struts-resume application, this configuration is located at metadata/web/servlets.xml: action org.apache.struts.action.ActionServlet config /WEB-INF/struts-config.xml config/upload /WEB-INF/struts-upload.xml debug 2 detail 2 2 This configuration indicates that there are two modules in this application the default module, which has no forward slash (/) in its name, and the second, our upload feature. The configuration files for both modules are located in the WEB-INF directory. The recommended standard for naming module configuration files is struts-module.xml. While you re looking at the ActionServlet s configuration, we want to point out a few changes between 1.0 and 1.1/1.2. In 1.0, it was common practice to specify the ResourceBundle

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

CHAPTER 15 USING STRUTS, XDOCLET, AND OTHER

CHAPTER 15 USING STRUTS, XDOCLET, AND OTHER TOOLS 619 that it s easier to do our job with this knowledge. If editing XML files by hand, we recommend XMLSpy (http://www.xmlspy.com). This is a great tool for any XML-related development because it validates your XML against a DTD or XML Schema and also performs auto-completion as you type. Another reason to learn the DTDs or Xml Schema is because tools like XDoclet assemble the struts-config.xmlfile from a number of XML fragments, and most IDE tools only support editing fully assembled struts-config.xml files. There are also applications that have been created simply to provide a development environment for Struts s application development. Let s take a look at a couple of these now. Struts Console Struts Console (found at http://www.jamesholmes.com/struts/) is a free application for managing Struts-based applications. Struts Console is a visual editor for JSP Tag Library, Struts, Tiles, and Validator configuration files. It can be used as a stand-alone Swing application or as a plug-in for your favorite IDE. Supported IDEs are JBuilder (v4.0+), Eclipse (v1.0+), IBM WebSphere Appl. Dev. (v4.0.3+), IDEA (v3.0, build 668+), NetBeans (v3.2), Sun ONE/Forte (v3.0+), and JDeveloper (v9i+). It has support for managing all your Struts-related XML files, such as struts-config.xml, tiles-config.xml, and validation.xml. When using this tool, as with many others, you ll lose any formatting you ve applied to the document. However, it does allow formatting within the tool to pretty up your XML. It also has a wizard for converting JSP and HTML pages into Struts JSP pages a very handy feature if you re converting an existing application to Struts. Easy Struts The Easy Struts project (see http://easystruts.sourceforge.net/) provides a set of tools for Struts development, including a struts-config.xmleditor, XSLT generation, tooltips from the Struts DTD, support for modules, and an input helper. Easy Struts is only available as an IDE plug-in; no stand-alone application is available. Supported IDEs are Eclipse (v2.0+) and JBuilder (v5.0+). Using Modules in Team Development Environments Have you ever worked on a project where many developers were working on the same codebase? Many development teams work in this type of environment, while others allocate development roles to single individuals. Let s imagine two types of teams; the first has fifteen developers and the second has three individuals. We ll pretend that both teams are developing similar applications that use Struts and EJBs for handling credit card payments for a large bank. The large team will probably divide the work among tiers, where five people work on each tier EJBs, ActionServlets, and business layer, and the web tier comprising JSP pages or Velocity templates. The second (smaller) team will simply assign one person to each tier. In a team environment where many people are configuring and manipulating deployment descriptors, it can be difficult to keep your web.xml and struts-config.xml in sync. The simplest solution we ve found is to use XDoclet to generate these configuration files, but there is another option modules. When initially developed by the Struts development team, they were called subapplications, which is a more descriptive name. Modules allow you to separate different areas of an application out into different modules. Modules are a core feature of Struts 1.1 and can be very helpful for large projects as well as for creating pluggable features.

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

616 CHAPTER 15 USING STRUTS, XDOCLET, AND

618 CHAPTER 15 USING STRUTS, XDOCLET, AND OTHER TOOLS Figure 15-14. Using a Tiles controller, the application can track the number of sessions and display that number in the header. You can see that the Tiles controller can be a very valuable asset in your Struts toolbox. You can reduce the amount of code needed in your actions and move specific logic to specific tiles. You might even eliminate the need to chain actions together, using multiple tiles and controller combinations instead. You re encouraged to consider using controllers because they can greatly help organize your code and view logic. By using controllers, actions can focus on page flow rather than preparing views. If you re developing a very small and simple application, Tiles might not be necessary. The difficult part of Tiles is finding a good example to operate from and extend. We hope that these examples, in combination with the struts-resume application, will make your Struts development journey easier. You should be able to use the basicLayout.jsp and tiles-config.xml files to get up and running. If you already know Struts and aren t using Tiles, you owe it to yourself (and your deadlines) to try it out. Using IDEs and Struts Development Environments We used to use Macromedia s HomeSite and vi for all our Java editing, because we hated the bloat and RAM wastage of an IDE. Furthermore, IDEs always seemed to complicate things more than they helped. With the maturity of tools like IDEA and Eclipse, using an IDE is fun again and worth our time (a gig of RAM doesn t hurt either). We ve never felt the need to use an IDE to help us configure our struts-config.xml or web.xml file. However, this was probably because these tools didn t exist when we first started working with Struts and web application. Now we re glad we learned the DTDs and we feel

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