100% found this document useful (1 vote)
54 views

Core JavaServer Faces 3rd ed Edition David Geary download

The document provides information about the book 'Core JavaServer Faces' by David Geary, which is available for download in various formats. It includes links to other related titles and outlines the structure and content of the book, including chapters on managed beans, navigation, standard JSF tags, and more. The book is designed to help readers understand JavaServer Faces and web application development.

Uploaded by

grapinluecke
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
54 views

Core JavaServer Faces 3rd ed Edition David Geary download

The document provides information about the book 'Core JavaServer Faces' by David Geary, which is available for download in various formats. It includes links to other related titles and outlines the structure and content of the book, including chapters on managed beans, navigation, standard JSF tags, and more. The book is designed to help readers understand JavaServer Faces and web application development.

Uploaded by

grapinluecke
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

Core JavaServer Faces 3rd ed Edition David Geary

pdf download

https://ebookname.com/product/core-javaserver-faces-3rd-ed-
edition-david-geary/

Get Instant Ebook Downloads – Browse at https://ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

The Faces of Terrorism David V. Canter

https://ebookname.com/product/the-faces-of-terrorism-david-v-
canter/

Microwave engineering 3rd ed Edition David M Pozar

https://ebookname.com/product/microwave-engineering-3rd-ed-
edition-david-m-pozar/

The child surveillance handbook 3rd ed Edition David


Elliman

https://ebookname.com/product/the-child-surveillance-
handbook-3rd-ed-edition-david-elliman/

Paradoxes of Modernization Unintended Consequences of


Public Policy Reform 1st Edition Helen Margetts

https://ebookname.com/product/paradoxes-of-modernization-
unintended-consequences-of-public-policy-reform-1st-edition-
helen-margetts/
The Structure of Philosophical Discourse A Genre and
Move Analysis 1st Edition Kyle Lucas

https://ebookname.com/product/the-structure-of-philosophical-
discourse-a-genre-and-move-analysis-1st-edition-kyle-lucas/

Encyclopedia of Substance Abuse 2 Volume Set

https://ebookname.com/product/encyclopedia-of-substance-
abuse-2-volume-set/

Willie Morris An Exhaustive Annotated Bibliography and


a Biography 1st Edition Jack Bales

https://ebookname.com/product/willie-morris-an-exhaustive-
annotated-bibliography-and-a-biography-1st-edition-jack-bales/

Human Heredity Principles and Issues 9th Edition


Michael R. Cummings

https://ebookname.com/product/human-heredity-principles-and-
issues-9th-edition-michael-r-cummings/

The Unofficial Guide to Flipping Properties Unofficial


Guides 1st Edition Peter A. Richmond

https://ebookname.com/product/the-unofficial-guide-to-flipping-
properties-unofficial-guides-1st-edition-peter-a-richmond/
Encyclopedia of CAMPS AND GHETTOS 1933 1945 Vol 1 Part
B Early Camps Youth Camps and Concentration Camps and
Subcamps under the SS Business Administration Main
Office WVHA 1st Edition Geoffrey P. Megargee
https://ebookname.com/product/encyclopedia-of-camps-and-
ghettos-1933-1945-vol-1-part-b-early-camps-youth-camps-and-
concentration-camps-and-subcamps-under-the-ss-business-
administration-main-office-wvha-1st-edition-geoffrey-p-mega/
FACELETS PAGE LAYOUT RADIO BUTTONS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" page.xhtml
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <h:selectOneRadio value="#{bean1.condiment}>
<html xmlns="http://www.w3.org/1999/xhtml" <f:selectItems value="#{bean1.choices}" var="it"
xmlns:f="http://java.sun.com/jsf/core" itemLabel="#{it.description}"
xmlns:h="http://java.sun.com/jsf/html" itemValue="#{it.productId}"/>
xmlns:ui="http://java.sun.com/jsf/facelets"> </h:selectOneRadio>
<h:head>...</h:head>
<h:body>
<h:form> WEB-INF/classes/com/corejsf/SampleBean.java
... public class SampleBean {
</h:form> public Collection<Condiment> getChoices() { ...}
</h:body> public int getCondiment() { ... }
</html> public void setCondiment(int value) { ... }
...
TEXT FIELD }

WEB-INF/classes/com/corejsf/Condiment.java
page.xhtml public class Condiment {
public String getDescription() { ... }
<h:inputText value="#{bean1.luckyNumber}"> public int getProductId() { ... }
}
WEB-INF/classes/com/corejsf/SampleBean.java
@Named("bean1") // or @ManagedBean(name="bean1")
CONVERSION
@SessionScoped <h:outputText value="#{bean1.amount}">
public class SampleBean { <f:convertNumber type="currency"/>
public int getLuckyNumber() { ... } </h:outputText>
public void setLuckyNumber(int value) { ... }
... The number is displayed with currency symbol and
} group separator: $1,000.00

BUTTON VALIDATION
Using the bean validation framework (JSR 303)
public class SampleBean {
page.xhtml @Max(1000) private BigDecimal amount;
}
<h:commandButton value="press me" action="#{bean1.login}"/>
Page-level validation and conversion
WEB-INF/classes/com/corejsf/SampleBean.java
<h:inputText value="#{bean1.amount}" required="true">
public class SampleBean {
<f:validateDoubleRange maximum="1000"/>
public String login() {
</h:inputText>
if (...) return "success"; else return "error";
}
... Error messages
}
The outcomes success and error can be mapped to pages
in faces-config.xml. If no mapping is specified, the page Amount
/success.xhtml or /error.xhtml is displayed. <h:inputText id="amt" label="Amount" value="#{bean1.amount}"/>
<h:message for="amt"/>
GET REQUESTS
<f:metadata> RESOURCES
<f:viewParam name="item" value="#{bean1.currentItem}"/>
<f:viewParam name="userId" value="#{bean1.user}"/> page.xhtml
</f:metadata> <h:outputStylesheet library="css" name="styles.css"/>
Request parameters set bean properties before the ...
<h:message for="amt" errorClass="errors">
page is rendered.
<h:button value="Continue" outcome="#{bean1.continueOutcome}" resources/css/styles.css
includeViewParams="true"/>
.errors {
The getContinueOutcome method is called when the button is font-style: italic;
rendered. The view parameters are added to the color: red;
request URL. }

From the Library of Wow! eBook


core
JAVASERVER FACES™

THIRD EDITION

From the Library of Wow! eBook


This page intentionally left blank

From the Library of Wow! eBook


core
JAVASERVER FACES ™

THIRD EDITION

DAVID GEARY
CAY HORSTMANN

Upper Saddle River, NJ • Boston • Indianapolis • San Francisco


New York • Toronto • Montreal • London • Munich • Paris • Madrid
Capetown • Sydney • Tokyo • Singapore • Mexico City

From the Library of Wow! eBook


Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where
those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed
with initial capital letters or in all capitals.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective
owners.
The authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any
kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in
connection with or arising out of the use of the information or programs contained herein.
This document is provided for information purposes only and the contents hereof are subject to change without notice. This doc-
ument is not warranted to be error-free, nor subject to any other warranties or conditions, whether expressed orally or implied
in law, including implied warranties and conditions of merchantability or fitness for a particular purpose. We specifically dis-
claim any liability with respect to this document and no contractual obligations are formed either directly or indirectly by this
document. This document may not be reproduced or transmitted in any form or by any means, electronic or mechanical, for any
purpose, without our prior written permission.
The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include
electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests.
For more information, please contact:
U.S. Corporate and Government Sales
(800) 382-3419
[email protected]
For sales outside the United States, please contact:
International Sales
[email protected]
Visit us on the Web: informit.com/ph
Library of Congress Cataloging-in-Publication Data
Geary, David M.
Core JavaServer faces / David Geary, Cay Horstmann.—3rd ed.
p. cm.
Includes index.
ISBN 978-0-13-701289-3 (pbk. : alk. paper)
1. JavaServer pages. 2. Web site development. 3. Web sites—Design.
I. Horstmann, Cay S., 1959- II. Title.
TK5105.8885.J38G433 2010
006.7'8—dc22
2010011569

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.


500 Oracle Parkway, Redwood Shores, CA 94065
All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be
obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any
means, electronic, mechanical, photocopying, recording, or likewise.
For information regarding permissions, write to:
Pearson Education, Inc.
Rights and Contracts Department
501 Boylston Street, Suite 900
Boston, MA 02116
Fax: (617) 671-3447
ISBN-13: 978-0-13-701289-3
ISBN-10: 0-13-701289-6
Text printed in the United States on recycled paper at Edwards Brothers in Ann Arbor, Michigan.
First printing, May 2010

From the Library of Wow! eBook


Contents

Preface xv
Acknowledgments xix

1 GETTING STARTED 2
Why JavaServer Faces? 3
A Simple Example 4
Ingredients 7
Directory Structure 8
Building a JSF Application 9
Deploying a JSF Application 11
Development Environments for JSF 13
An Analysis of the Sample Application 15
Beans 16
JSF Pages 17
Servlet Configuration 19
A First Glimpse of Ajax 21
JSF Framework Services 24
Behind the Scenes 26
Rendering Pages 27

From the Library of Wow! eBook


vi Contents

Decoding Requests 28
The Life Cycle 29
Conclusion 31

2 MANAGED BEANS 32
Definition of a Bean 33
Bean Properties 36
Value Expressions 37
Backing Beans 38
CDI Beans 39
Message Bundles 40
Messages with Variable Parts 42
Setting the Application Locale 43
A Sample Application 45
Bean Scopes 51
Session Scope 52
Request Scope 53
Application Scope 54
Conversation Scope 54
View Scope 55
Custom Scopes 56
Configuring Beans 56
Injecting CDI Beans 56
Injecting Managed Beans 57
Bean Life Cycle Annotations 58
Configuring Managed Beans with XML 58
The Expression Language Syntax 63
Lvalue and Rvalue Modes 63
Using Brackets 64
Map and List Expressions 65
Calling Methods and Functions 66
Resolving the Initial Term 67
Composite Expressions 69

From the Library of Wow! eBook


Contents vii

Method Expressions 70
Method Expression Parameters 71
Conclusion 71

3 NAVIGATION 72
Static Navigation 73
Dynamic Navigation 74
Mapping Outcomes to View IDs 75
The JavaQuiz Application 77
Redirection 86
Redirection and the Flash 87
RESTful Navigation and Bookmarkable URLs 88
View Parameters 89
GET Request Links 90
Specifying Request Parameters 91
Adding Bookmarkable Links to the Quiz Application 92
Advanced Navigation Rules 96
Wildcards 97
Using from-action 98
Conditional Navigation Cases 99
Dynamic Target View IDs 99
Conclusion 99

4 STANDARD JSF TAGS 100


An Overview of the JSF Core Tags 102
Attributes, Parameters, and Facets 104
An Overview of the JSF HTML Tags 105
Common Attributes 107
Panels 115
The Head, Body, and Form Tags 118
Form Elements and JavaScript 120
Text Fields and Text Areas 123
Hidden Fields 127

From the Library of Wow! eBook


viii Contents

Using Text Fields and Text Areas 127


Displaying Text and Images 131
Buttons and Links 134
Using Buttons 136
Using Command Links 141
Selection Tags 145
Checkboxes and Radio Buttons 148
Menus and Listboxes 151
Items 153
Messages 171
Conclusion 177

5 FACELETS 178
Facelets Tags 179
Templating with Facelets 181
Building Pages from Common Templates 183
Organizing Your Views 187
Decorators 193
Parameters 195
Custom Tags 195
Components and Fragments 198
Loose Ends 198
<ui:debug> 198
<ui:remove> 200
Handling Whitespace 202
Conclusion 202

6 DATA TABLES 204


The Data Table Tag—h:dataTable 205
A Simple Table 207
h:dataTable Attributes 210
h:column Attributes 211
Headers, Footers, and Captions 212

From the Library of Wow! eBook


Contents ix

Styles 215
Styles by Column 215
Styles by Row 216
The ui:repeat Tag 217
JSF Components in Tables 218
Editing Tables 222
Editing Table Cells 222
Deleting Rows 225
Database Tables 228
Table Models 232
Rendering Row Numbers 233
Finding the Selected Row 234
Sorting and Filtering 234
Scrolling Techniques 242
Scrolling with a Scrollbar 242
Scrolling with Pager Widgets 243
Conclusion 244

7 CONVERSION AND VALIDATION 246


Overview of the Conversion and Validation Process 247
Using Standard Converters 249
Conversion of Numbers and Dates 249
Conversion Errors 253
A Complete Converter Example 259
Using Standard Validators 262
Validating String Lengths and Numeric Ranges 262
Checking for Required Values 264
Displaying Validation Errors 265
Bypassing Validation 266
A Complete Validation Example 267
Bean Validation 270
Programming with Custom Converters and Validators 275
Implementing Custom Converter Classes 275

From the Library of Wow! eBook


x Contents

Specifying Converters 279


Reporting Conversion Errors 280
Getting Error Messages from Resource Bundles 281
The Custom Converter Sample Application 286
Supplying Attributes to Converters 289
Implementing Custom Validator Classes 290
Registering Custom Validators 290
Validating with Bean Methods 294
Validating Relationships between Multiple
Components 295
Implementing Custom Converter and Validator Tags 297
Conclusion 303

8 EVENT HANDLING 304


Events and the JSF Life Cycle 306
Value Change Events 307
Action Events 312
Event Listener Tags 318
The f:actionListener and f:valueChangeListener
Tags 318
Immediate Components 320
Using Immediate Input Components 321
Using Immediate Command Components 323
Passing Data from the UI to the Server 324
Method Expression Parameters 325
The f:param Tag 325
The f:attribute Tag 326
The f:setPropertyActionListener Tag 327
Phase Events 328
System Events 329
Multi-Component Validation 331
Making Decisions before Rendering the View 333
Putting It All Together 338
Conclusion 345

From the Library of Wow! eBook


Contents xi

9 COMPOSITE COMPONENTS 346


The Composite Tag Library 348
Using Composite Components 350
Implementing Composite Components 352
Configuring Composite Components 353
Attribute Types 354
Required Attributes and Default Attribute Values 355
Manipulating Server-Side Data 356
Localizing Composite Components 359
Exposing a Composite’s Components 360
Exposing Action Sources 363
Facets 365
Children 366
JavaScript 368
Backing Components 373
Packaging Composite Components in JARs 382
Conclusion 383

10 AJAX 384
Ajax and JSF 386
The JSF Life Cycle and Ajax 387
The JSF Ajax Recipe 388
The f:ajax Tag 389
Ajax Groups 392
Ajax Field Validation 394
Ajax Request Monitoring 396
JavaScript Namespaces 398
Handling Ajax Errors 400
Ajax Responses 400
The JSF 2.0 JavaScript Library 403
Passing Additional Ajax Request Parameters 405
Queueing Events 407
Coalescing Events 408

From the Library of Wow! eBook


xii Contents

Intercepting jsf.ajax.request() 409


Using Ajax in Composite Components 409
Conclusion 416

11 CUSTOM COMPONENTS, CONVERTERS,


AND VALIDATORS 418
Implementing a Component Class 420
Encoding: Generating Markup 424
Decoding: Processing Request Values 427
The Tag Library Descriptor 433
Using an External Renderer 438
Processing Tag Attributes 441
Supporting Value Change Listeners 442
Supporting Method Expressions 443
Queuing Events 445
The Sample Application 445
Encoding JavaScript 453
Using Child Components and Facets 457
Processing SelectItem Children 460
Processing Facets 461
Using Hidden Fields 462
Saving and Restoring State 468
Partial State Saving 469
Building Ajax Components 473
Implementing Self-Contained Ajax in
Custom Components 475
Supporting f:ajax in Custom Components 479
Conclusion 484

12 EXTERNAL SERVICES 486


Database Access with JDBC 487
Issuing SQL Statements 487
Connection Management 489

From the Library of Wow! eBook


Contents xiii

Plugging Connection Leaks 490


Using Prepared Statements 491
Transactions 493
Using the Derby Database 493
Configuring a Data Source 495
Accessing a Container-Managed Resource 495
Configuring a Database Resource in GlassFish 496
Configuring a Database Resource in Tomcat 498
A Complete Database Example 499
Using the Java Persistence Architecture 507
A Crash Course in JPA 507
Using JPA in a Web Application 508
Using Managed Beans and Stateless Session Beans 513
Stateful Session Beans 517
Container-Managed Authentication and Authorization 519
Sending Mail 532
Using Web Services 537
Conclusion 544

13 HOW DO I . . . ? 546
How do I find more components? 547
How do I support file uploads? 548
How do I show an image map? 557
How do I produce binary data in a JSF page? 559
How do I show a large data set, one page at a time? 568
How do I generate a pop-up window? 573
How do I selectively show and hide parts of a page? 581
How do I customize error pages? 582
How do I write my own client-side validation tag? 588
How do I configure my application? 595
How do I extend the JSF expression language? 596
How do I add a function to the JSF expression
language? 599

From the Library of Wow! eBook


xiv Contents

How do I monitor the traffic between the browser


and the server? 601
How do I debug a stuck page? 602
How do I use testing tools when developing a JSF
application? 604
How do I use Scala with JSF? 605
How do I use Groovy with JSF? 607
Conclusion 608

Index 609

From the Library of Wow! eBook


Preface

When we heard about JavaServer Faces (JSF) at the 2002 JavaOne conference,
we were very excited. Both of us had extensive experience with client-side Java
programming—David in Graphic Java™, and Cay in Core Java™, both published
by Sun Microsystems Press—and we found web programming with servlets
and JavaServer Pages (JSP) to be rather unintuitive and tedious. JSF promised
to put a friendly face in front of a web application, allowing programmers to
think about text fields and menus instead of dealing with page flips and
request parameters. Each of us proposed a book project to our publisher, who
promptly suggested that we should jointly write the Sun Microsystems Press
book on JSF.
In 2004, the JSF Expert Group (of which David is a member) released the JSF 1.0
specification and reference implementation. A bug fix 1.1 release emerged
shortly afterward, and an incremental 1.2 release added a number of cleanups
and convenience features in 2006.
The original JSF specification was far from ideal. It was excessively general,
providing for use cases that turned out to be uninteresting in practice. Not
enough attention was given to API design, forcing programmers to write com-
plex and tedious code. Support for GET requests was clumsy. Error handling
was plainly unsatisfactory, and developers cursed the “stack trace from hell”.
JSF had one saving grace, however. It was highly extensible, and therefore it
was very attractive to framework developers. Those framework developers

xv

From the Library of Wow! eBook


xvi Preface

built cutting edge open-source software that plugged into JSF, such as Facelets,
Ajax4jsf, Seam, JSF Templates, Pretty Faces, RichFaces, ICEFaces, and so on.
JSF 2.0, released in 2009, is built on the experience of those open-source frame-
works. Nearly all of the original authors of the aforementioned frameworks
participated on the JSF 2 Expert Group, so JSF 2.0, unlike JSF 1.0, was forged
from the crucible of real-world open-source projects that had time to mature.
JSF 2.0 is much simpler to use and better integrated into the Java EE technology
stack than JSF 1.0. Almost every inch of JSF 1.0 has been transformed in JSF 2.0
in some way for the better. In addition, the specification now supports new
web technologies such as Ajax and REST.
JSF is now the preeminent server-side Java web framework, and it has fulfilled
most of its promises. You really can design web user interfaces by putting com-
ponents on a form and linking them to Java objects, without having to mix
code and markup. A strong point of JSF is its extensible component model, and
a large number of third-party components have become available. The flexible
design of the framework has allowed it to grow well and accommodate new
technologies.
Because JSF is a specification and not a product, you are not at the mercy of a
single vendor. JSF implementations, components, and tools are available from
multiple sources. We are very excited about JSF 2.0, and we hope you will share
in this excitement when you learn how this technology makes you a more
effective web application developer.

About This Book


This book is suitable for web developers whose main focus is on implementing
user interfaces and business logic. This is in stark contrast to the official JSF
specification, a dense and pompously worded document whose principal audi-
ence is framework implementors, as well as long-suffering book authors. JSF is
built on top of servlets, but from the point of view of the JSF developer, this
technology merely forms the low-level plumbing. While it can't hurt to be
familiar with servlets, JSP, or Struts, we do not assume any such knowledge.
The first half of the book, extending through Chapter 7, focuses on the JSF tags.
These tags are similar to HTML form tags. They are the basic building blocks
for JSF user interfaces. Anyone with basic HTML skills (for web page design)
and standard Java programming (for the application logic) can use the JSF tags
to build web applications.

From the Library of Wow! eBook


Preface xvii

The first part of the book covers these topics:


• Setting up your programming environment (Chapter 1)
• Connecting JSF tags to application logic (Chapter 2)
• Navigating between pages (Chapter 3)
• Using the standard JSF tags (Chapter 4)
• Using Facelets tags for templating (Chapter 5) NEW
• Data tables (Chapter 6)
• Converting and validating input (Chapter 7)
Starting with Chapter 8, we begin JSF programming in earnest. You will learn
how to perform advanced tasks, and how to extend the JSF framework. Here
are the main topics of the second part:
• Event handling (Chapter 8)
• Building composite components—reusable components with
sophisticated behavior that are composed from simpler components
(Chapter 9) NEW
• Ajax (Chapter 10) NEW
• Implementing custom components (Chapter 11)
• Connecting to databases and other external services (Chapter 12)
We end the book with a chapter that aims to answer common questions of the
form “How do I . . . ?” (Chapter 13). We encourage you to have a peek at that
chapter as soon as you become comfortable with the basics of JSF. There are
helpful notes on debugging and logging, and we also give you implementation
details and working code for features that are missing from JSF, such as file
uploads, pop-up menus, and a pager component for long tables.
All chapters have been revised extensively in this edition to stress the new and
improved features of JSF 2.0. Chapters 5, 9, and 10 are new to this edition.

Required Software
All software that you need for this book is freely available. You can use an
application server that supports Java EE 6 (such as GlassFish version 3) or a
servlet runner (such as Tomcat 6) together with a JSF implementation. The
software runs on Linux, Mac OS X, Solaris, and Windows. Both Eclipse and
NetBeans have extensive support for JSF development with GlassFish or
Tomcat.

From the Library of Wow! eBook


xviii Preface

Web Support
The web site for this book is http://corejsf.com. It contains:
• The source code for all examples in this book
• Useful reference material that we felt is more effective in browseable form
than in print
• A list of known errors in the book and the code
• A form for submitting corrections and suggestions

From the Library of Wow! eBook


Acknowledgments

First and foremost, we'd like to thank Greg Doench, our editor at Prentice Hall,
who has shepherded us through this project, never losing his nerve in spite of
numerous delays and complications. Many thanks to Vanessa Moore for turn-
ing our messy manuscript into an attractive book and for her patience and
amazing attention to detail.
We very much appreciate our reviewers for this and previous editions who
have done a splendid job, finding errors and suggesting improvements in
various drafts of the manuscript. They are:
• Gail Anderson, Anderson Software Group, Inc.
• Larry Brown, LMBrown.com, Inc.
• Damodar Chetty, Software Engineering Solutions, Inc.
• Frank Cohen, PushToTest
• Brian Goetz, Sun Microsystems, Inc.
• Rob Gordon, Crooked Furrow Farm
• Marty Hall, author of Core Servlets and JavaServer Pages™, Second Edition,
(Prentice Hall, 2008)
• Steven Haines, CEO/Founder, GeekCap, Inc.
• Charlie Hunt, Sun Microsystems, Inc.
• Jeff Langr, Langr Software Solutions
• Jason Lee, Senior Java Developer, Sun Microsystems, Inc.

xix

From the Library of Wow! eBook


xx Acknowledgments

• Bill Lewis, Tufts University


• Kito Mann, author of JavaServer Faces in Action (Manning, 2005) and
founder of JSFCentral.com
• Jeff Markham, Markham Software Company
• Angus McIntyre, IBM Corporation
• John Muchow, author of Core J2ME™ (Prentice Hall, 2001)
• Dan Shellman, BearingPoint
• Sergei Smirnov, principal architect of Exadel JSF Studio
• Roman Smolgovsky, Flytecomm
• Stephen Stelting, Sun Microsystems, Inc.
• Christopher Taylor, Nanshu Densetsu
• Kim Topley, Keyboard Edge Limited
• Michael Yuan, coauthor of JBoss® Seam: Simplicity and Power Beyond Java™
EE (Prentice Hall, 2007)
Finally, thanks to our families and friends who have supported us through this
project and who share our relief that it is finally completed.

From the Library of Wow! eBook


core
JAVASERVER FACES™

THIRD EDITION

From the Library of Wow! eBook


GETTING STARTED

Topics in This Chapter

• “Why JavaServer Faces?” on page 3


• “A Simple Example” on page 4
• “Development Environments for JSF” on page 13
• “An Analysis of the Sample Application” on page 15
• “A First Glimpse of Ajax” on page 21
• “JSF Framework Services” on page 24
• “Behind the Scenes” on page 26

From the Library of Wow! eBook


Chapter 1

Why JavaServer Faces?


Nowadays, you can choose among many frameworks for developing the user
interface of a web application. JavaServer Faces (JSF) is a component-based
framework. For example, if you want to display a table with rows and col-
umns, you do not generate HTML tags for rows and cells in a loop, but you
add a table component to a page. (If you are familiar with client-side Java
development, you can think of JSF as “Swing for server-side applications.”) By
using components, you can think about your user interface at a higher level
than raw HTML. You can reuse your own components and use third-party
component sets. And you have the option of using a visual development envi-
ronment in which you can drag and drop components onto a form.
JSF has these parts:
• A set of prefabricated UI (user interface) components
• An event-driven programming model
• A component model that enables third-party developers to supply
additional components
Some JSF components are simple, such as input fields and buttons. Others are
quite sophisticated—for example, data tables and trees.

From the Library of Wow! eBook


Another Random Document on
Scribd Without Any Related Topics
I knew I would not have long to wait, for in the still night the hoof-
beats were now ringing on the road. Whoever it was, he rode fast and
upon a matter of moment. Presently the figure of the flying horse and
rider appeared dimly. Then they grew more distinct. The rider was
leaning upon his horse's neck, and as they rushed down upon us I saw
that it was a woman. Great was my surprise at the sight.
My first impulse was to rein aside, but when the woman came within
twenty feet of me she raised her face a little, and then I saw that it
was Mary Desmond, the Tory. Even in that faint light I could see that
her face was strained and anxious, and I was struck with a great
wonderment.
I turned my horse into the middle of the road, and she was compelled
to rein her own back so suddenly that he nearly fell upon his
haunches.
"Out of my way!" she cried. "Why do you stop me?"
"I think you will admit, Miss Desmond," I said, "that the meeting is
rather unusual, and that surprise, if nothing else, might justify my
stopping you."
"Why is it strange that I am here?" she demanded, in a high tone.
"Why is it more strange than your presence here at this time?"
"I am riding forward to join a detachment of the American army which
I believe is encamped not much farther on," I said.
In reassuming my proper American character I had forgotten that I still
wore the British garb.
"Why are you doing that?" she asked, quickly and keenly.
"I wish to take them a message," I replied.
"Who are you, and what are you?" she asked, abruptly, turning upon
me a look before which my eyes fell,—"you whose garb is English and
speech American."
"Whatever I am at other times," I replied, "to-night I am your servant
only."
"Then," she replied, in a voice that thrilled me, "come with me. I ride
to warn the Americans that they are threatened with destruction."
"You!" I exclaimed, my surprise growing. "You warn them! You, the
most bitter of Tories, as bitter as only a woman can be!"
She laughed a laugh that was half of triumph, half of scorn.
"I have deceived you too, as I have deceived all the others," she said.
"But I should not boast. The part was not difficult, and I despised it.
Come! we will waste no more time. Ride with me to the American
army, if you are what you have just boasted yourself to be."
Her voice was that of command, and I had no mind to disobey it.
"Come," I cried, "I will prove my words."
"I know the way," she replied. "I will be the guide."
We galloped away side by side. Many thoughts were flying through my
head. I understood the whole story at once, or thought I did, which
yielded not less of satisfaction to me. She was not the Tory she had
seemed to be, any more than I was the Briton whose uniform I had
taken. Why she had assumed such a rôle it was not hard to guess.
Well, I was glad of it. My spirits mounted to a wonderful degree, past
my ability to account for such a flight. But I bothered myself little
about it. Another time would serve better for such matters.
The hoof-beats rang on the flinty road, and our horses stretched out
their necks as our pace grew swifter and we fled on through the night.
"How far do we ride?" I asked.
"The American encampment is four miles beyond," she said. "The
British force is coming down on the right. Pray God we may get there
in time!"
"Amen!" said I. "But, if we do not, it will not be for lack of haste."
We passed a cottage close by the roadside. The clatter of our horses'
hoofs aroused its owner, for in those troublous times men slept lightly.
A night-capped head was thrust out of a window, and I even noted the
look of wonderment on the man's face; but we swept by, and the man
and his cottage were soon lost in the darkness behind us.
"It will take something more than that to stop us to-night," I cried, in
the exuberance of my spirits.
Miss Desmond's face was bent low over her horses neck, and she
answered me not; but she raised her head and gave me a look that
showed the courage a true woman sometimes has.
We were upon level ground now, and I thought it wise to check our
speed, for Miss Desmond had ridden far and fast, and her horse was
panting.
"We will not spare the horse," she said. "The lives of the patriots are
more precious."
"But by sparing the former we have more chance of saving the latter,"
I said; and to that argument only would she yield. The advantage of it
was soon seen, for when we increased our speed again the horses
lengthened their stride and their breath came easier.
"Have you heard the sound of arms?" she asked. "Surely if any attack
had been made we could hear it, even as far as this, in the night."
"I have heard nothing," I replied, "save the noise made by the
galloping of our own horses. We are not yet too late."
"No, and we will not be too late at any time," she said, with sudden
energy. "We cannot—we must not be too late!"
"How strong is the American force?" I asked.
"Strong enough to save itself, if only warned in time," she replied.
We came to a shallow brook which trickled peacefully across the road.
Our horses dashed into it, and their flying hoofs sent the water up in
showers. But almost before the drops could fall back into their native
element we were gone, and our horses' hoofs were again ringing over
the stony road.
Before us stretched a strip of forest, through the centre of which the
road ran. In a few moments we were among the trees. The boughs
overhung the way and shut out half of the moon's light. Beyond, we
could see the open country again, but before we reached it a
horseman spurred from the wood and cried to us to halt, flourishing
his naked sword before him.
We were almost upon him, but on the instant I knew Belfort, and he
knew me.
"Out of the way!" I cried. "On your life, out of the way!"
"You traitor! You damned traitor!" he shouted, and rode directly at me.
He made a furious sweep at my head with his sabre, but I bent low,
and the blade circled over me, whistling as it passed. The next
moment, with full weight and at full speed, my horse struck his, and
Belfort's went down, the shriek from the man and the terrified neigh
from the horse, mingling as they fell.
With a snort of triumph, my horse leaped clear of the fallen and
struggling mass, and then we were out of the forest, Mary Desmond
still riding by my side, her head bent over her horse's neck as if she
were straining her eyes for a sight of the patriots who were still two
miles and more away.
"You do not ask me who it was," I said.
"I know," she replied; "and I heard also what he called you."
"'Tis true, he called me that," I replied. "But he is in the dust now, and
I still ride!"
We heard musket-shots behind us, and a bullet whizzed uncomfortably
near. So Belfort had not been alone. In the shock of our rapid collision
I had not had the time to see; but these shots admitted of no doubt.
"We will be pursued," I said.
"Then the greater the need of haste," she replied. "We cannot spare
our horses now. There is a straight road before us."
No more shots were fired at us just then. Our pursuers must have
emptied their muskets; but the clatter of the horses' hoofs told us that
they were hot on the chase. Our own horses were not fresh, but they
were of high mettle, and responded nobly to our renewed calls upon
them. Once I took an anxious look behind me, and saw that our
pursuers numbered a dozen or so. They were riding hard, belaboring
their mounts, with hands and feet, and I rejoiced at the sight, for I
knew the great rush at the start would tell quickly upon them.
"Will they overtake us?" asked Mary Desmond.
"It is a matter of luck and speed," I replied, "and I will answer your
question in a quarter of an hour. But remember that, come what may, I
keep my word to you. I am your servant to-night."
"Even if your self-sought slavery takes you into the American lines?"
she asked.
"Even so," I replied. "I told you my mission, though you seemed to
believe it not."
With this the time for conversation passed, and I put my whole
attention upon our flight. My loaded pistol was still in my belt, and if
our pursuers came too near, a bullet whistling among them might
retard their speed. But I held that for the last resort.
So far as I could see, the men were making no attempt to reload their
muskets, evidently expecting to overtake us without the aid of bullets.
I inferred from this circumstance that Belfort, whom I had disabled,
had been the only officer among them. Otherwise they would have
taken better measures to stop us. Nevertheless they pursued with
patience and seemingly without fear. By and by they fell to shouting.
They called upon us to stop and yield ourselves prisoners. Then I
heard one of them say very distinctly that he did not want to shoot a
woman. Mary Desmond heard it too, for she said,—
"I ask no favor because I am a woman. If they should shoot me, ride
on with my message."
I did not think it wise to reply to this, but spoke encouragingly to her
horse. He was panting again, and his stride was shortening, but his
courage was still high. He was a good horse and true, and deserved to
bear so noble a burden.
Presently the girl's head fell lower upon the horse's neck, and I called
hastily to her, for I feared that she was fainting.
"'Twas only a passing weakness," she said, raising her head again. "I
have ridden far to-night; but I can ride farther."
The road again led through woods, and for a moment I thought of
turning aside into the forest; but reflection showed me that in all
likelihood we would become entangled among the trees, and then our
capture would be easy. So we galloped straight ahead, and soon
passed the strip of wood, which was but narrow. Then I looked back
again, and saw that our pursuers had gained. They were within easy
musket-range now, and one of the men, who had shown more
forethought than the others and reloaded his piece, fired at us. But the
bullet touched neither horse nor rider, and I laughed at the wildness of
his aim. A little farther on a second shot was fired at us, but, like the
other, it failed of its mission.
Now I noted that the road was beginning to ascend slightly and that
farther on rose greater heights. This was matter of discouragement;
but Miss Desmond said briefly that beyond the hill-top the American
encampment lay. If we could keep our distance but a little while now,
her message would be delivered. Even in the hurry of our flight I
rejoiced that the sound of no fire-arms save those of our pursuers had
yet been heard, which was proof that the attack upon the Americans
had not yet been made.
The road curved a little now and became much steeper. Our pursuers
set up a cry of triumph. They were near enough now for us to hear
them encouraging each other, I could measure the distance very well,
and I saw that they were gaining faster than before. The crest of the
hill was still far ahead. These men must be reminded not to come too
near, and I drew my pistol from my belt.
As the men came into better view around the curve, I fired at the
leader. It chanced that my bullet missed him, but, what was a better
thing for us, struck his horse full in the head and killed him. The
stricken animal plunged forward, throwing his rider over his head. Two
or three other horsemen stumbled against him, and the entire troop
was thrown into confusion. I struck Miss Desmond's horse across the
flank with my empty pistol, and then treated my own in like fashion. If
we were wise, we would profit by the momentary check of our
enemies, and I wished to neglect no opportunity. Our good steeds
answered to the call as well as their failing strength would permit. The
crest of the hill lay not far before us now, and I felt sure that if we
could but reach it, the British would pursue us no farther.
But when I thought that triumph was almost achieved, Miss Desmond's
horse began to reel from side to side. He seemed about to fall from
weakness, for, of a truth, he had galloped far that night, and had done
his duty as well as the best horse that ever lived, be it Alexander's
Bucephalus or any other. Even now he strove painfully, and looked up
the hill with distended eyes, as if he knew where the goal lay. His rider
seemed smitten with an equal weakness, but she summoned up a little
remaining strength against it, and raised herself up for the final
struggle.
"Remember," she said again to me, "if I fail, as most like I will, you are
to ride on with my message."
"I have been called a traitor to-night," I said, "but I will not be called
the name I would deserve if I were to do that."
"It is for the cause," she said. "Ride and leave me."
"I will not leave you," I cried, thrilling with enthusiasm. "We will yet
deliver the message together."
She said no more, but sought to encourage her horse. The troopers
had recovered from their confusion, and, with their fresher mounts,
were gaining upon us in the most alarming manner. I turned and
threatened them with my empty pistol, and they drew back a little; but
second thought must have assured them that the weapon was not
loaded, for they laughed derisively and again pressed their horses to
the utmost.
"Do as I say," cried Miss Desmond, her eyes flashing upon me. "Leave
me and ride on. There is naught else to do."
But my thought was to turn my horse in the path and lay about me
with the sword. I could hold the troopers while she made her escape
with the message that she had borne so far already. I drew the blade
from the scabbard and put a restraining hand upon my horse's rein.
"What would you do?" cried Miss Desmond.
"The only thing that is left for me to do," I replied.
"Not that!" she cried; "not that!" and made as if she would stop me.
But, even while her voice was yet ringing in my ears, a dozen rifles
flashed from the hill-top, a loud voice was heard encouraging men to
speedy action, and a troop came galloping forward to meet us. In an
instant the Englishmen who were not down had turned and were
fleeing in a panic of terror down the hill and over the plain.
"You are just in time, captain," cried Miss Desmond, as the leader of
the rescuing band, a large, dark man, came up. Then she reeled, and
would have fallen from her horse to the ground had not I sprung down
and caught her.
Chapter Twenty—The Night Combat
But Miss Desmond was the victim only of a passing weakness, and I
was permitted to hold her in my arms but for a moment. Then she
demanded to be placed upon the ground, saying that her strength had
returned. I complied of necessity; and turning to the American captain,
who was looking curiously at us, she inquired,—
"Captain, the American force, is it safe?" "Yes, Miss Desmond," he
replied; and I wondered how he knew her. "It is just over the hill there.
The night had been quiet until you came galloping up the hill with the
Englishmen after you."
"Then we are in time!" she cried, in a voice of exultation. "Lose not a
moment, captain. A British force much exceeding our own in strength
is even now stealing upon you."
The message caused much perturbation, as well it might, and a half-
dozen messengers were sent galloping over the hill. Then the captain
said,—
"Miss Desmond, you have done much for the cause, but more to-night
than ever before."
But she did not hear him, for she fell over in a faint.
"Water!" I cried. "Some water! She may be dying!"
"Never mind about water," said the captain, dryly. "Here is something
that is much better for woman, as well as for man, in such cases."
He produced a flask, and, raising Miss Desmond's head, poured some
fiery liquid in her mouth. It made her cough, and presently she revived
and sat up. She was very pale, but there was much animation in her
eye.
"You have sent the warning, captain, have you not?" she asked, her
mind still dwelling upon the object for which she had come.
"Do not fear, Miss Desmond," said the leader, gravely. "Our people
know now, and they will be ready for the enemy when they come,
thanks to your courage and endurance."
Then he beckoned to me, and we walked a bit up the hill-side, leaving
Miss Desmond sitting on the turf and leaning against a tree.
"A noble woman," said the captain, looking back at her.
"Yes," said I, fervently.
"It was a lucky fortune that gave you such companionship to-night," he
continued.
"Yes," replied I, still with fervor.
"Lieutenant Chester," he said, "that is not the only particular in which
fortune has been kind to you to-night."
"No," I replied, with much astonishment at the patness with which he
spoke my true name.
"I have said," he continued, with the utmost gravity, "that fortune has
been very kind to-night to Lieutenant Robert Chester, of the American
army. I may add that it has been of equal kindness to Lieutenant
Melville, of the British army."
"Who are you, and what are you?" I cried, facing about, "and why do
you speak in such strange fashion?"
"I do not think it is strange at all," he said, a light smile breaking over
his face. "So far as I am concerned, it is a matter of indifference,
Lieutenant Chester or Lieutenant Melville: which shall it be?"
I saw that it was useless for me to pretend more. He knew me, and
was not to be persuaded that he did not. So I said,—
"Let it be Lieutenant Robert Chester, of the American army. The name
and the title belong to me, and I feel easier with them than with the
others. I have not denied myself. Now, who are you, and why do you
know so much about me?"
"Nor will I deny myself, either," he said, a quiet smile dwelling upon his
face. "I am William Wildfoot, captain of rangers in the American army."
"What! are you the man who has been incessantly buzzing like a wasp
around the British?" I cried.
"I have done my humble best," he said, modestly; "I even chased you
and your friend Lieutenant Marcel into Philadelphia. For which I must
crave your forgiveness. Your uniforms deceived me; but since then we
have become better acquainted with each other."
"How? I do not understand," I said, still in a maze.
"Perhaps you would know me better if I were to put on a red wig," he
said. "Do not think, Lieutenant Chester, that you and Lieutenant Marcel
are the only personages endowed with a double identity."
I looked at him closely, and I began to have some glimmering of the
truth.
"Yes," he said, when he saw the light of recognition beginning to
appear upon my face, "I am Waters. Strange what a difference a red
wig makes in one's appearance. But I have tried to serve you and your
friend well, and I hope I have atoned for my rudeness in putting you
and Lieutenant Marcel to such hurry when I first saw you. It is true
that I have had a little sport with you. I thought that you deserved it
for your rashness, but I have not neglected your interests. I warned
Alloway in the jail not to know you, and I helped him to escape. I
learned about you from Pritchard, but no one else knows. I bound you,
too, in Sir William Howe's room, but I leave it to you yourself that it
was necessary."
His quiet laugh was full of good nature, though there was in it a slight
tinge of pardonable vanity. Evidently this was a man much superior to
the ordinary partisan chieftain.
"Then you too have placed your neck in the noose?" I said.
"Often," he replied. "And I have never yet failed to withdraw it with
ease."
"I have withdrawn mine," I said, "and it shall remain withdrawn."
"Not so," he replied. "Miss Desmond must return to her father and
Philadelphia. It is not fit that she should go alone, and no one but you
can accompany her."
I had believed that nothing could induce me to take up the character
of Lieutenant Melville of the British army again, but I had not thought
of this. I could not leave Miss Desmond to return alone through such
dangers to the city.
"Very well," I said, "I will go back."
"I thought so," returned Wildfoot, with a quick glance at me that
brought the red blood to my face. "But I would advise you to bring
Miss Desmond to the crest of the hill and wait for a while. I must hurry
away, for my presence is needed elsewhere."
The partisan was like a war-horse sniffing the battle; and, leaving Miss
Desmond, myself, and two good, fresh horses on the hill-top, he
hastened away. I was not averse to waiting, for I expected that a sharp
skirmish would occur. I had little fear for the Americans now, for in a
night battle, where the assaulted are on their guard, an assailing force
is seldom successful, even though its superiority in arms and numbers
be great.
From the hill-top we saw a landscape of alternate wood and field, amid
which many lights twinkled. A hum and murmur came up to us and
told me that the Americans were profiting by their warning and would
be ready for the enemy.
"You can now behold the result of your ride," I said to Miss Desmond,
who stood by my side, gazing with intent eyes upon the scene below,
which was but half hidden by the night. She was completely recovered,
or at least seemed to be so, for she stood up, straight, tall, and self-
reliant.
"We were just in time," she said.
"But in good time," I added.
"I suppose we shall see a battle," she said. "I confess it has a strange
attraction for me. Perhaps it is because I am not near enough to mark
its repellent phases."
She made no comment upon my British uniform and my apparent
British character. She did not appear to remark anything incongruous in
my appearance there, and it was not a subject that I cared to raise.
"See, the fighting must have begun," she said, pointing to a strip of
wood barely visible in the night.
Some streaks of flame had leaped up, and we heard a distant rattle
which I knew must be the small arms at work. Then there was a lull for
a moment, followed by a louder and a longer crackle, and a line of fire,
flaming up and then sinking in part, ran along the edge of the woods
and across the fields. Through this crackle came a steady rub-a-dub,
rub-a-dub.
"That is the beat of the drums," I said to Miss Desmond, who turned
an inquiring face to me. "The drum is the soldier's conscience, I
suppose, for it is always calling upon him to go forward and fight."
I spoke my thoughts truly, for the drum has always seemed to me to
be a more remorseless war-god than the cannon. With its steady and
tireless thump, thump, it calls upon you, with a voice that will not be
hushed, to devote yourself to death. "Come on! Come on! Up to the
cannon! Up to the cannon!" it says. It taunts you and reviles you. Give
this drum to a ragamuffin of a little boy, and he catches its spirit, and
he goes straight forward with it and commands you to follow him. It
was so at Long Island when the Maryland brigade sacrificed itself and
held back the immense numbers of the enemy until our own army
could escape. A scrap of a boy stood on a hillock and beat a drum as
tall as himself, calling upon the Maryland men to stand firm and die,
until a British cannon-ball smashed his drum, and a British grenadier
hoisted him over his shoulder with one hand and carried him away.
There is a league between the drum and the cannon. The drum lures
the men up to the cannon, and then the monster devours them.
Above the crackle rose the louder notes of the field-pieces, and then I
thought I heard the sound of cheering, but I was not sure. We could
see naught of this dim and distant battle but the flame of its
gunpowder. The night was too heavy for any human figure to appear in
its just outline; and I saw that I would have to judge of its progress by
the shifting of the line of fire. The British attack was delivered from the
left, and the blaze of the musketry extended along a line about a half-
mile in length. Though while the light was leaping high at one place it
might be sinking low at another, yet this line was always clearly
defined, and we could follow its movements well enough.
The line was stationary for full fifteen minutes, and from that
circumstance we could tell that the Americans had profited well by the
warning and were ready to receive the attack. Still, the action was
sharper and contested with more vigor than I had expected. Having
made the attack, the British seemed disposed to persist in it for a while
at least. But presently the line of fire began to bend back towards the
west at the far end.
"The British are retreating!" exclaimed Miss Desmond.
"At one point, so it would seem," I said.
"Yes, and at other points too," she cried. "See, the centre of the fiery
line bends back also."
This was true, for the centre soon bent back so far that the whole line
was curved like a bow. Then the eastern end yielded also, and soon
was almost hidden in some woods, where it made but a faint quivering
among the trees. In truth, along the whole line the fire was dying. The
sputter of the musketry was but feeble and scarce heard, and even the
drum seemed to lose spirit and call but languidly for slaughter.
"The battle is nearly over, is it not?" asked Miss Desmond.
"Yes," I replied, "though we could scarce call it a battle. Skirmish is a
better name. I think that line of fire across there will soon fade out
altogether."
I chanced to be a good prophet in this instance, for in five minutes the
last flash had gone out and there was naught left but a few echoes. It
was clear that the British had suffered repulse and had withdrawn, and
it was not likely that the Americans would follow far, for such an
undertaking would expose them to destruction.
I now suggested to Miss Desmond that it would be the part of wisdom
for us to begin our return to Philadelphia, and we were preparing for
departure, when we heard the approach of horsemen, and in a
moment or two Wildfoot and three of his men approached. "It was not
a long affair," said the leader, "though there was some smart
skirmishing for a while. When they found that we were ready, and
rather more than willing, they soon drew off, and they are now on the
march for Philadelphia. I tell you again, Miss Desmond, that you have
ridden bravely to-night, and this portion of the American army owes its
salvation to you."
"My ride was nothing more than every American woman owes to her
country," replied Miss Desmond.
"True," replied Wildfoot, "though few would have had the courage to
pay the debt. But I have come back mainly to say that some of my
scouts have brought in Lieutenant Belfort, sorely bruised, but not
grievously hurt, and that he will have no opportunity to tell the English
of your ride to-night, Miss Desmond, at least not until he is
exchanged."
I had forgotten all about Belfort, and his capture was a lucky chance
for both of us. As for the other Englishmen who had pursued us, I had
no fear that they would recognize me, even if they saw me in the
daylight, and they had seen me but dimly in a hot and flurried pursuit.
Captain Wildfoot raised his hat to us with all the courtesy of a
European nobleman and rode away with his men, while we turned our
horses towards Philadelphia, and were soon far from the hill on which
we had stood and witnessed the battle's flare. Miss Desmond knew the
way much better than I did, and I followed her guidance, though we
rode side by side.
"You do not ask me to keep this matter a secret," I said, at length,
when we had ridden a mile or more in silence.
"Is not your own safety as much concerned as mine?" she asked,
looking with much meaning at my gay British uniform.
"Is that the only reason you do not ask me to speak of it?" I said, still
bent upon going deeper into the matter.
"Will you speak of it when I ask you not to do so?" she said.
I did not expect such a question, but I replied in the negative with
much haste. But presently I said, thinking to compliment her, that,
however my own sympathies might be placed, I must admit that she
had done a very brave deed, and that I could not withhold my
admiration. But she replied with some curtness that Captain Wildfoot
had said that first,—which was true enough, though I had thought it as
early as he. Had it been any other woman, I would have inferred from
her reply that her vanity was offended. But it was not possible to think
such a thing of Mary Desmond on that night.
"Have you any heart for this task?" she asked me, with much
suddenness, a few minutes later.
"What task?" I replied, surprised.
"The task that the king has set for his army,—the attempt to crush the
Colonies," she replied.
There was much embarrassment in the question for me, and I sought
to take refuge in compliment.
"That you are enlisted upon the other side, Miss Desmond," I replied,
"is enough to weaken the attachment of any one to the king's service."
"This is not a drawing-room," she replied, looking at me with clear
eyes, "nor has the business which we have been about to-night any
savor of the drawing-room. Let us then drop such manner of speech."
She was holding me at arm's length, but I made some rambling,
ambiguous reply, to the effect that a soldier should have no opinions,
but should do what he is told to do,—which, though a very good
argument, does not always appease one's conscience. But she did not
press the question further,—which was a relief to me.
When we became silent again, my thoughts turned back to our
successful ride. On the whole, I had cause for lightness of feeling.
Aided by chance or luck, I had come out of difficulties wondrous well.
Within a very short space I had seen our people twice triumph over the
British, and I exulted much because of it.
I think I had good reason for my exultation aside from the gain to our
cause from these two encounters. While accusing us of being boasters,
the British had quite equalled us at anything of that kind. I think it was
their constant assumption of superiority, rather more than the tea at
the bottom of Boston Harbor, that caused the war. Then they came
over and said we could not fight. They are much better informed on
that point now, though I will admit that they showed their own
courage and endurance too.
Our return journey was not prolific of events. The night seemed to
have exhausted its fruitfulness before that time. When we were within
a short distance of the British lines, Miss Desmond pointed to a low
farmhouse almost hidden by some trees.
"That is my retreat for the present," she said. "It was from that house I
started, and I will return to it. For many reasons, I cannot be seen
riding into Philadelphia with you at this hour."
"But are the inhabitants of that house friends of yours?" I asked, in
some protest.
"They can be trusted to the uttermost," she replied briefly. "They have
proved it. You must not come any farther with me. I have a pass and I
can come into the city when I wish without troublesome explanations."
"Then I will leave you," I replied, "since I leave you in safety; but I
hope you will not forget that we have been friends and allies on this
expedition."
"I will not forget it," she said. Then she thanked me and rode away, as
strong and upright and brave as ever. I watched her until she entered
the trees around the house and disappeared. Then, although I might
have fled to the American camp, I turned towards Philadelphia, a much
wiser man than I was earlier in the night.
Some of the stragglers were coming into the city already, and it was
not difficult for me, with my recent practice in lying, to make
satisfactory explanation concerning myself. I told a brave tale about
being captured by the rebels in the rush, my escape afterwards, and
my futile attempts to rejoin the army. Then I passed on to my
quarters.
In the course of the day the entire detachment, save those who had
been killed or wounded in the skirmish, returned, and I learned that Sir
William was much mortified at the complete failure of the expedition.
He could not understand why the rebels were in such a state of
readiness. I was very uneasy about Marcel, but he rejoined me
unharmed, although he admitted that he had been in much trepidation
several times in the course of the night.
Chapter Twenty-one—Keeping up
Appearances
I wished to hold further conversation with Marcel that morning on a
matter of high interest to both of us, but I did not find the opportunity,
for we were sent on immediate duty into different parts of the suburbs.
Mine was soon finished, and I returned to the heart of the city. I
noticed at once that the invading army had suffered a further
relaxation of discipline. Evidently, after his failure of the preceding
night, Sir William took no further interest in the war, and but little in
the army, for that matter, except where his personal friends were
concerned. But most afflicting was the condition of mind into which the
Tories had fallen. Philadelphia, like New York, abounded in these
gentry, and a right royal time they had been having, basking in the
sunshine of British favor, and tickling themselves with visions of honors
and titles, and even expecting shares in the confiscated estates of their
patriot brethren.
Now they were in sore distress, and but little of my pity had they.
Among the rumors was one, and most persistent it was too, that a
consequence of the French alliance would be the speedy evacuation of
Philadelphia by the British, who would in all probability seek to
concentrate their strength at New York. This was a misfortune that the
wretched Tories had never foreseen. What! the British ever give up
anything they had once laid their hands upon! The descendants of the
conquerors of Crecy, Poitiers, and Agincourt, the grandsons of the men
who had humbled Louis the Great at Blenheim and Malplaquet, to be
beaten by untrained, half-armed, and starving farmers! The thing was
impossible. And Tory and Briton vied with each other in crying to all
the winds of heaven that it could not be. The British were most
arrogant towards us in those days, for which reason we always took
much satisfaction in beating them, admitting at the same time that
they were brave men, and we never cared much about our victories
over the Hessians, who, to tell the truth, were very fierce in the pursuit
of a beaten enemy, but not quite so enduring in the main contention as
the British.
But I had ever had more animosity against the Tories than the British,
and I felt much secret delight at their manifest and troublous state of
mind. Some, who had their affairs well in hand, were preparing to
depart with their beloved British, who little wanted such burdens.
Others were mourning for their houses and goods which they had
expected to see wrenched from them as they would have wrenched
theirs from the patriots. All seemed to expect that the American army
would be upon them immediately, such were their agitation and terror.
Curses, too, were now heard against King George for deserting his
faithful servants after making so many great promises to them. Well, it
is not for those who shake the dice and lose, to complain. We, too, had
had our sufferings.
Nevertheless, the British, as is their wont, put a good face upon the
matter. That very night, many of the officers were at a reception given
with great splendor at the house of a rich Tory, and they talked of past
triumphs and of others soon to be won. I also was there, for I had
contrived to secure an invitation, having special reasons for going.
As I had expected, Miss Desmond was present. She seemed to neglect
none of the fashionable gayeties of the city, and to me she looked
handsomer and statelier than ever. I wished for some look, some
suggestion that we had been companions in danger, and that we were
rather better friends than the others present; but she was cold and
proud, and there was nothing in her manner to show that we had ever
met, save in the formal atmosphere of the drawing-room.
"I hear, Lieutenant Melville," she said, "that you were in the
unfortunate attack last night and fell into the hands of the rebels."
"Yes, Miss Desmond," I replied, "but good fortune succeeded bad
fortune. I escaped from them in the darkness and the confusion, and
am back in Philadelphia to lay my sword at your feet."
Such was the polite language of the time; but she received it with
small relish, for she replied, with asperity,—
"You have barely escaped laying your sword at the feet of the rebels.
Is not that enough of such exercise?"
Then some British officers, who heard her, laughed as if the gibe had
no point for them.
I had no further opportunity for conversation with her until much later
in the evening. The rooms were buzzing with the gossip of great
events soon to occur; and though I sought not the part of a spy, and
had no intent to put myself in such a position, I listened eagerly to the
fragments of news that were sent about. This was not a matter of
difficulty, for all were willing, even eager, to talk, and one could not but
listen, without drawing comment and giving offence.
"'Tis reported," said Symington, a colonel, to me, "that the French king
will despatch an army in great haste to America. But we shall not care
for that—shall we, Melville? I, for one, am tired of playing hide-and-
seek with the old fox, Mr. Washington, and should like to meet our
ancient foes the French regulars in the open field. Then the fighting
would be according to the rules as practised by the experts in Europe
for many generations."
I thought to throw cold water upon him, and said I feared the
Americans and the French allied might prove too strong for us; and as
for the ancient rules of war, campaigns must be adapted to their
circumstances and the nature of the country in which they are
conducted. If the Americans alone, and that too when at least one-
third of them were loyal to our cause, had been able to confine us to
two or three cities practically in a state of besiegement, what were we
to expect when the full might of the King of France arrived to help
them?
But he would have naught of my argument. He was full of the idea that
glory was to be found fighting the French regulars in the open field
according to the rules of Luxembourg and Marlborough. But I have no
right to complain, for it was such folly as his that was of great help to
us throughout the war, and contributed to the final victory over the
greatest power and the best soldiers of Europe.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like