Chapter 3: Tabs and Accordions 43 Using a

Chapter 3: Tabs and Accordions 43 Using a jQuery tab plugin 44 Client-side code 45 Server-side considerations 49 Using jQuery accordion plugins 49 Client-side code 50 Server-side management of accordions 53 Client-side code 54 Server-side code 55 Just the conversion 56 Now show the data with the accordions 57 Server-side management of tabs 58 Server-side code 58 Just the conversion 59 Now show the data with the tabs 60 Using special codes to define tabs 61 Client-side code 63 Server-side code 63 Loading accordion panels through Ajax 66 Client-side code 67 Server-side code 69 Loading tab panels through Ajax 69 Client-side code 69 Summary 71 Chapter 4: Forms and Form Validation 73 Using the jQuery validation plugin 74 Client-side code 74 Setting up jQuery validation from PHP 77 Server-side code (setup) 77 Client-side code 78 Server-side code 79 Remote validation 81 Server-side code (setup) 81 Client-side code 82 Server-side code 83 Large select boxes 84 Client-side code 85 Server-side code 86 [ ii ]

Table of Contents Preface 1 Chapter 1: Introduction

Table of Contents Preface 1 Chapter 1: Introduction and Overview 7 Expected developer skills 8 Differences between PHP and JavaScript 9 What is jQuery? 10 Why jQuery? 12 How does jQuery fit in with PHP? 13 How to work with the examples 14 Projects that use PHP and jQuery 16 WordPress 16 RoundCube 16 KFM 17 Drupal 18 Summary 18 Chapter 2: Quick Tricks 19 Dynamic select boxes 21 Client-side code 22 How it works 23 Server-side code 25 Quick deletes 26 Client-side code 27 Server-side code 30 Contextual help 31 Inline editing 36 Client-side code 36 Server-side code 41 Summary 41

About the Reviewers Akash Mehta is a web

About the Reviewers Akash Mehta is a web application developer and technical author based in Australia. His area of work covers e-learning solutions, information systems, and developer training. He regularly writes web development articles for Adobe, CNet, the APC Magazine, and other print and online publications. He is a regular speaker at IT conferences, user groups, and BarCamps. Currently, Akash provides various services like web development, technical writing, consulting, and training through his website, Hailing from an igloo somewhere up in Canada, Ashok Modi is currently a systems analyst for California Institute of the Arts ( He was a systems (and games) programmer for zinc Roe Design (, and has been working with Drupal for the last three years. Starting from Drupal 4.6, he is the author of the abuse module (and looking for co-maintainers!), and has helped many maintainers in updating their contributed modules from 4.7.x to 5.x to 6.x. He also helped organize DrupalCamp Toronto in 2007 and 2008 and recently presented multiple sessions at DrupalCamp LA in 2009. In his spare time, Ashok tries to help contributed module maintainers with features and bugs. He was a technical reviewer on another book, Drupal 6 Social Networking, also published by Packt Publishing. I would like to thank my wife, Richa, for letting me obsess over technology and pushing me to freelance and try other open-source technologies in my spare time. John K. Murphy is a graduate of the University of West Virginia and has been wrapped up in computers and software development since the 1980s. When he is not buried in a book or jumping out of an airplane, he works as an IT consultant. John lives with his wife and two children in Pittsburgh, PA and is currently obsessing about the Internet of Things.

About the Author Kae Verens lives in Monaghan,

About the Author Kae Verens lives in Monaghan, Ireland with his wife Bronwyn and their two kids Jareth and Boann. He has been programming for twenty years, fifteen of which were as a professional. Kae started writing in JavaScript in the mid nineties, and started working on the server-side languages a few years later. After writing CGI in C and Perl, Kae switched to PHP in 2000, and has worked with it since then. Kae is currently the secretary of the Irish PHP Users’ Group,, is part-owner of the Irish web-development company,, and is the author of popular web-based file-manager KFM, In his spare time, Kae plays the guitar, juggles, is learning to play the piano, and likes to occasionally dust the skateboard off and mess around on it. I would like to thank Packt Publishing for considering me for this project; it’s been a journey, and I’ve learned quite a lot from it. I would also like to thank for hiring me way back in 2001, when I was a brash programmer, eager to show how things should be done. And finally, I’d like to thank Bronwyn and the kids for putting up with the days and hours that I’ve had to avoid them to concentrate on the book!

Credits Author Kae Verens Reviewers Akash Mehta Ashok

Credits Author Kae Verens Reviewers Akash Mehta Ashok Modi John K. Murphy Acquisition Editor Douglas Paterson Development Editor Darshana D. Shinde Technical Editor Ishita Dhabalia Copy Editor Sanchari Mukherjee Editorial Team Leader Gagandeep Singh Project Team Leader Lata Basantani Project Coordinator Srimoyee Ghoshal Proofreader Chris Smith Indexer Rekha Nair Production Coordinator Dolly Dasilva Cover Work Dolly Dasilva

jQuery 1.3 with PHP Copyright 2009 Packt

jQuery 1.3 with PHP Copyright 2009 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, Packt Publishing, nor its dealers or 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 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: October 2009 Production Reference: 1211009 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-847196-98-9 Cover Image by Louise Barr (

jQuery 1.3 with PHP Enhance your PHP applications

jQuery 1.3 with PHP Enhance your PHP applications by increasing their responsiveness through jQuery and its plugins Kae Verens BIRMINGHAM – MUMBAI

The Hibernate interfaces contexts and can (Web site designers) even automatically

The Hibernate interfaces contexts and can even automatically store the disconnected context for you (in a stateful EJB session bean) between requests. We ll get back to conversations later in the book and show you all the details about the two implementation strategies. You don t have to choose one right now, but you should be aware of the consequences these strategies have on object state and object identity, and you should understand the necessary transitions in each case. We now explore the persistence manager APIs and how you make the theory behind object states work in practice. 9.3 The Hibernate interfaces Any transparent persistence tool includes a persistence manager API. This persistence manager usually provides services for the following: Basic CRUD (create, retrieve, update, delete) operations Query execution Control of transactions Management of the persistence context The persistence manager may be exposed by several different interfaces. In the case of Hibernate, these are Session, Query, Criteria, and Transaction. Under the covers, the implementations of these interfaces are coupled tightly together. In Java Persistence, the main interface you interact with is the EntityManager; it has the same role as the Hibernate Session. Other Java Persistence interfaces are Query and EntityTransaction (you can probably guess what their counterpart in native Hibernate is). We ll now show you how to load and store objects with Hibernate and Java Persistence. Sometimes both have exactly the same semantics and API, and even the method names are the same. It s therefore much more important to keep your eyes open for little differences. To make this part of the book easier to understand, we decided to use a different strategy than usual and explain Hibernate first and then Java Persistence. Let s start with Hibernate, assuming that you write an application that relies on the native API.
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

CHAPTER 9 Working with objects requirements that equality

CHAPTER 9 Working with objects requirements that equality be both symmetric and transitive in this case; and, more important, the business key may not correspond to any well-defined candidate natural key in the database (subclass properties may be mapped to a different table). You may have also noticed that the equals() and hashCode() methods always access the properties of the other object via the getter methods. This is extremely important, because the object instance passed as other may be a proxy object, not the actual instance that holds the persistent state. To initialize this proxy to get the property value, you need to access it with a getter method. This is one point where Hibernate isn t completely transparent. However, it s a good practice to use getter methods instead of direct instance variable access anyway. Let s switch perspective now and consider an implementation strategy for conversations that doesn t require detached objects and doesn t expose you to any of the problems of detached object equality. If the identity scope issues you ll possibly be exposed to when you work with detached objects seem too much of a burden, the second conversation-implementation strategy may be what you re looking for. Hibernate and Java Persistence support the implementation of conversations with an extended persistence context: the session-per-conversation strategy. 9.2.4 Extending a persistence context A particular conversation reuses the same persistence context for all interactions. All request processing during a conversation is managed by the same persistence context. The persistence context isn t closed after a request from the user has been processed. It s disconnected from the database and held in this state during user think-time. When the user continues in the conversation, the persistence context is reconnected to the database, and the next request can be processed. At the end of the conversation, the persistence context is synchronized with the database and closed. The next conversation starts with a fresh persistence context and doesn t reuse any entity instances from the previous conversation; the pattern is repeated. Note that this eliminates the detached object state! All instances are either transient (not known to a persistence context) or persistent (attached to a particular persistence context). This also eliminates the need for manual reattachment or merging of object state between contexts, which is one of the advantages of this strategy. (You still may have detached objects between conversations, but we consider this a special case that you should try to avoid.) In Hibernate terms, this strategy uses a single Session for the duration of the conversation. Java Persistence has built-in support for extended persistence
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

Object identity and equality return username.hashCode(); } } (Web hosting uk)

Object identity and equality return username.hashCode(); } } For some other classes, the business key may be more complex, consisting of a combination of properties. Here are some hints that should help you identify a business key in your classes: Consider what attributes users of your application will refer to when they have to identify an object (in the real world). How do users tell the difference between one object and another if they re displayed on the screen? This is probably the business key you re looking for. Every attribute that is immutable is probably a good candidate for the business key. Mutable attributes may be good candidates, if they re updated rarely or if you can control the situation when they re updated. Every attribute that has a UNIQUE database constraint is a good candidate for the business key. Remember that the precision of the business key has to be good enough to avoid overlaps. Any date or time-based attribute, such as the creation time of the record, is usually a good component of a business key. However, the accuracy of System.currentTimeMillis() depends on the virtual machine and operating system. Our recommended safety buffer is 50 milliseconds, which may not be accurate enough if the time-based property is the single attribute of a business key. You can use database identifiers as part of the business key. This seems to contradict our previous statements, but we aren t talking about the database identifier of the given class. You may be able to use the database identifier of an associated object. For example, a candidate business key for the Bid class is the identifier of the Item it was made for together with the bid amount. You may even have a unique constraint that represents this composite business key in the database schema. You can use the identifier value of the associated Item because it never changes during the lifecycle of a Bid setting an already persistent Item is required by the Bid constructor. If you follow our advice, you shouldn t have much difficulty finding a good business key for all your business classes. If you have a difficult case, try to solve it without considering Hibernate after all, it s purely an object-oriented problem. Notice that it s almost never correct to override equals() on a subclass and include another property in the comparison. It s a little tricky to satisfy the
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

WeBlog about developing JSP, Apache, PHP5 and web site hosting