Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Practical JSF in Java EE 8
Nội dung xem thử
Mô tả chi tiết
Michael Müller
Practical JSF in Java EE 8
Web Applications in Java for the
Enterprise
Michael Müller
Brühl, Nordrhein-Westfalen, Germany
Any source code or other supplementary material referenced
by the author in this book is available to readers on GitHub via
the book's product page, located at
www.apress.com/9781484230299 . For more detailed
information, please visit www.apress.com/source-code .
ISBN 978-1-48423029-9
e-ISBN 978-1-4842-3030-5
https://doi.org/10.1007/978-1-4842-3030-5
Library of Congress Control Number: 2018941459
© Michael Müller 2018
This work is subject to copyright. All rights are reserved by
the Publisher, whether the whole or part of the material is
concerned, specifically the rights of translation, reprinting,
reuse of illustrations, recitation, broadcasting, reproduction on
microfilms or in any other physical way, and transmission or
information storage and retrieval, electronic adaptation,
computer software, or by similar or dissimilar methodology
now known or hereafter developed.
Trademarked names, logos, and images may appear in this
book. Rather than use a trademark symbol with every
occurrence of a trademarked name, logo, or image we use the
names, logos, and images only in an editorial fashion and to
the benefit of the trademark owner, with no intention of
infringement of the trademark. The use in this publication of
trade names, trademarks, service marks, and similar terms,
even if they are not identified as such, is not to be taken as an
expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to
be true and accurate at the date of publication, neither the
authors nor the editors nor the publisher can accept any legal
responsibility for any errors or omissions that may be made.
The publisher makes no warranty, express or implied, with
respect to the material contained herein.
Distributed to the book trade worldwide by Springer Science+Business Media New
York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-
SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit
www.springeronline.com. Apress Media, LLC is a California LLC and the sole
member (owner) is Springer Science + Business Media Finance Inc (SSBM
Finance Inc). SSBM Finance Inc is a Delaware corporation.
To my wife Claudia and my kids:
Thank you for your patience during night-writing and
other long sessions.
I love you.
Preface
Developing web applications with Java and JavaServer Faces
(JSF) had been a great pleasure (and success) to me for a
couple of years when I realized first wanted to write a book
about JSF in late 2010. I got in touch with some German
publishers with the goal of writing around 200–250 pages
about this subject, nothing more. “No thanks, too special” was
one answer. The other: “Great. Add some more pages, another
thousand, and write about the whole Java Enterprise Edition.
Keep JSF smaller than 200 pages.” Frustrating answers.
So, I started to blog about JSF in early 2011. And I became
a member of the JSF 2.2 (JSR 344) Expert Group. Unlike most
of the other volunteers, I wasn’t a JSF implementer, but an
expert JSF user. I became a member of the JSF 2.3 (JSR 372)
Expert Group too. I’m still an expert JSF user, but I started to
code a bit within the JSF sources. If I’m accepted as an expert
group member for JSF’s next version, whatever it may be
called after the transition to the Eclipse Foundation, I want to
contribute code.
My tutorial on web development with JSF is still the most
popular part of my blog ( blog.mueller-bruehl.de ),
and I never gave up my intention to write a book about this
subject. Over time, I switched from blogging in German to
writing about development in mostly English. And that
German publisher would be happy to learn that I now write
about related Java EE stuff also.
With the articles of my blog as a solid foundation, I started
to write my book, Web Development with Java and JSF ,
which I first published myself in 2014 using Leanpub (
www.leanpub.com/jsf ). It became a kind of living
book. The first version only covered the fundamentals. Every
reader who purchased it was able to download later updates.
Thus, the book grew up.
In 2016 Apress first asked me to publish the book as is. I
declined, because I wanted to add more stuff. When they
asked me again in 2017, the book had reached such a stage
that I agreed. Of course, there is still more to write about, but
for every book you need to make a final decision on content.
Today, you hold in your hands an enhanced edition of my
former book. It follows the same approach, combining
theoretical background with practical development. The title
Practical JSF in Java EE 8 is a clue that it’s not only about
JSF — you can’t use this UI technology in isolation. Rather,
it’s embedded in a full stack of technologies we know as the
Java Enterprise Edition (Java EE). Java EE 8 was released on
September 21, 2017, and Oracle has begun its donation of Java
EE to the Eclipse Foundation. Even if future versions will be
called Jakarta EE, the latest version still is Java EE 8 with JSF
2.3. Because this book is about practical development, it
concentrates on applications, not on the latest features.
Although all applications in this book operate with Java EE 8,
most of the apps might be realized with Java EE 7, which is
still state-of-the-art in most enterprise environments. Only
those functions that rely on newer Java EE features need the
appropriate version — the last application described in this
book, Alumni, takes advantage of such new features.
In a sense, this book teaches you to develop Java EE
applications with JSF as user interface. It’s a book for Java
enthusiasts. Knowledge about web technologies is helpful, but
not required. For developers who aren’t familiar with HTML,
CSS, and other stuff, I’ve added some introductory chapters in
the appendixes.
Enjoy!
—Michael Müller
Acknowledgments
All content unless otherwise mentioned is written by me. But a
couple of people provided me feedback, helped with wording,
or did a technical review on TinyCalculator and/or Books.
Besides the people who are mentioned below, a special thank
you to John Wright, who also provided a couple of comments.
And a special thank you to all the other people who provided a
mostly one-time feedback. All of you helped to improve this
book.
Pratap Chatterjee is a software engineer who has worked
with enterprise application software development for over 20
years, mainly in the telecommunication industry in England
with BT and T-Mobile UK as programmer, designer,
developer, and team leader with Java and web technologies.
Currently Pratap lives in Sweden with his wife and two sons.
He’s working for Karolinska Institutet, one of the world’s
leading medical universities. Pratap enjoys programming, and
in his role as a programmer developer, he has written
applications that help in the publication of doctoral courses
and admission of students by the university. Pratap has also
reviewed technical articles and recently reviewed Grails in
Action , 2nd Edition (Manning, 2014), by Glen Smith and
Peter Ledbrook.
Constantin Marian Alin is a passionate Java developer
focused on developing web/desktop applications using the
latest Java technologies. Beside daily work and learning, in the
past few years he has written and published articles for the
Developer.com and DZone communities. Currently, he’s
focused on developing RIA/SPA applications for the GIS field
by integrating the power of Java frameworks like JavaServer
Faces, PrimeFaces, AngularJS, Bootstrap, RESTful, EJB, JPA,
and more with the GIS specialized software, such as ArcGIS,
OpenLayers, GeoServer, Google Maps, and others.
Anghel Leonard is a senior Java developer with more
than 13 years of experience in Java SE, Java EE, and related
frameworks. He’s written and published more than 50 articles
about Java technologies and more than 500 tips and tricks for
many websites dedicated to programming. In addition, he’s
written books including Pro Java 7 NIO.2 (Apress), Pro
Hibernate and MongoDB (Apress), Tehnologii XML XML în
Java (Albastra), Jboss Tools 3 Developer’s Guide (Packt
Publishing), JSF 2.0 Cookbook (Packt), JSF 2.0 Cookbook:
LITE (Packt), Mastering JavaServer Faces 2.2 (Packt).
Currently, Anghel is developing web applications using
the latest Java technologies on the market (EJB 3.0, CDI,
Spring, JSF, Struts, Hibernate, and so on). For the past two
years, he’s focused on developing rich Internet applications for
geographic information systems.
Special thanks to the reviewers of this edition, Manual
Jordan Elera and Mathew Moodie , who provided input to
refine and enhance this book.
Table of Contents
1. Part I: TinyCalculator
1.
1. Chapter 1: TinyCalculator
1. Creating the Application
2. Working with TinyCalculator
1. Managed Beans
2. The Page
3. The Relationship Between Code and View
3. Summary
2. Chapter 2: Foundations
1. Web Applications
2. HTTP
3. HTML
4. CSS
5. JavaScript
6. Java
7. Maven
8. Selenium and Arquillian
9. Servlet
10. Deployment
11. Summary
3. Chapter 3: JavaServer Faces
1. View Definition Language
2. Web vs. Traditional Application
3. JSF Lifecycle Overview
4. JSF Namespaces and Tags
5. Component Tree
6. Navigation
7. Summary
4. Chapter 4: Expression Language
1. Unified Expression Language
2. Value Expression
1. Operators
2. Dot and Square Bracket
3. Method Expression
4. Implicit Objects
5. Summary
5. Chapter 5: HTML-Friendly Markup
1. HTML-Friendly TinyCalculator
2. Summary
6. Chapter 6: Configuration Files
1. pom.xml
2. web.xml
3. faces-config.xml
4. beans.xml
5. persistence.xml
6. glassfish-resources.xml
7. glassfish-web.xml
8. Other Files
9. Summary
7. Chapter 7: Testing with Selenium
1. Selenium Overview
2. Preparing TinyCalculator
3. Creating the Test
4. Unit Test without Selenium
5. Summary
8. Chapter 8: TinyCalculator Recap
2. Part II: Books
1.
1. Chapter 9: Preparing for Java EE 8
1. Current Evolution
2. Upgrade the Application Server
3. Payara Server
4. Summary
2. Chapter 10: Introducing the Books Application
1. Books Requirements
2. Development Order
3. Summary
3. Chapter 11: Starting the Books App
1. Page Layout
1. HTML Structure
2. Basic Styling with CSS
2. Design First Data Model
3. First Dialog Box (Repeating Structure)
4. Summary
4. Chapter 12: Java Persistence API
1. Entities
2. Persistence Unit
1. Data Source
2. Entity Manager
3. Service Class