Apress.ZK.Ajax.Without.JavaScript.Framework.pdf

(2809 KB) Pobierz
374157802 UNPDF
374157802.001.png
ZK
Ajax Without JavaScript Framework
HENRI CHEN AND ROBBIE CHENG
374157802.002.png
ZK : Ajax Without JavaScript Framework
Copyright © 2007 by Potix Corporation
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic
or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the
prior written permission of the copyright owner and the publisher.
ISBN-13 (pbk): 978-1-59059-901-3
ISBN-10 (pbk): 1-59059-901-2
Printed and bound in the United States of America (POD)
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trade-
marked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc., in the US and
other countries. Apress, Inc., is not affiliated with Sun Microsystems, Inc., and this book was written without
endorsement from Sun Microsystems, Inc.
ZK and all ZK-based marks are trademarks or registered trademarks of Potix Corporation, in the US and other
countries.
Lead Editor: Steve Anglin
Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Jonathan Gennick, Jason Gilmore, Jonathan Hassell,
Chris Mills, Matthew Moodie, Jeffrey Pepper, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh,
Tony Campbell
Project Manager: Richard Dal Porto
Copy Edit Manager: Nicole Flores
Copy Editor: Heather Lang
Assistant Production Director: Kari Brooks-Copony
Compositor: Richard Ables
Cover Designer: Kurt Krames
Manufacturing Director: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York,
NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com , or visit
http://www.springeronline.com .
For information on translations, please contact Apress directly at 2855 Telegraph Avenue, Suite 600, Berkeley, CA
94705. Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com , or visit http://www.apress.com .
The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has
been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or
entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information
contained in this work.
The source code for this book is available to readers at http://www.apress.com in the Source Code/
Download section.
 
Contents
About the Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Part 1 ■■■ Getting to Know the ZK Ajax
Framework
CHAPTER 1
What Is the ZK Ajax Framework? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
ZK Ajax Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Ajax: Behind-the-Scenes Technology . . . . . . . . . . . . . . . . . . . . . . . 5
A Presentation Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
A Server-centric Event-Driven Framework . . . . . . . . . . . . . . . . . . . 7
A Component-Based GUI Toolkit. . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
CHAPTER 2
Getting Started with ZK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Installing the Java Runtime Environment . . . . . . . . . . . . . . . . . . . . . . . . 9
Installing the Java Servlet Container . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Using the Installer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Using the ZIP File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Deploying and Testing zkdemo-all.war . . . . . . . . . . . . . . . . . . . . . . . . . 11
Relative Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Configuring web.xml . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Configuring zk.xml . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
CHAPTER 3
Building Your First ZK Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Your First ZK Application: Hello World! . . . . . . . . . . . . . . . . . . . . . . . . . 17
The First ZK Component: Window. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Injecting Ajax to Your ZK Application . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
CHAPTER 4
Introducing the Versatile ZK Components . . . . . . . . . . . . . . . . . . . . . . . 29
Components, Pages, and Desktops. . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
The Component Life Cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
iii
374157802.003.png
iv
CONTENTS
The Life Cycle of a ZUML Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
The Page Initialization Phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
The Component Creation Phase . . . . . . . . . . . . . . . . . . . . . . . . . . 31
The Event Processing Phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
The Rendering Phase. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Updating Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
The Request Processing Phase . . . . . . . . . . . . . . . . . . . . . . . . . . 32
The Event Processing Phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
The Rendering Phase. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Component Garbage Collection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Using Component Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
The id Attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
The if and unless Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
The forEach Attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
The use Attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
ID Spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Getting a Fellow that’s Inside the ID Space. . . . . . . . . . . . . . . . . . 40
Getting a Component that’s Outside the ID Space . . . . . . . . . . . . 41
Getting a Component from Another Page . . . . . . . . . . . . . . . . . . . 43
Using zscript and EL expressions . . . . . . . . . . . . . . . . . . . . . . . . . 43
zscript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
EL Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
ZUML and XML Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Creating a Real Modal Dialog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Messagebox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Fileupload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Implementing Macro Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Integrating Mega Components . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Google Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
FCKeditor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Dojo. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Part 2 ■■■ Applying Your ZK Knowledge
Setting Up the Development Environment . . . . . . . . . . . . . . . . . . . . . . 57
Installing the Java SE (JDK) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Installing Tomcat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Installing the Eclipse IDE SDK. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
CHAPTER 5
 
Zgłoś jeśli naruszono regulamin