Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Java EE 8 Application Development
Java EE 8 Application Development

Java EE 8 Application Development: Develop Enterprise applications using the latest versions of CDI, JAX-RS, JSON-B, JPA, Security, and more

Arrow left icon
Profile Icon David R. Heffelfinger
Arrow right icon
zł39.99 zł177.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.1 (9 Ratings)
eBook Dec 2017 372 pages 1st Edition
eBook
zł39.99 zł177.99
Paperback
zł221.99
Subscription
Free Trial
Arrow left icon
Profile Icon David R. Heffelfinger
Arrow right icon
zł39.99 zł177.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.1 (9 Ratings)
eBook Dec 2017 372 pages 1st Edition
eBook
zł39.99 zł177.99
Paperback
zł221.99
Subscription
Free Trial
eBook
zł39.99 zł177.99
Paperback
zł221.99
Subscription
Free Trial

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Java EE 8 Application Development

JavaServer Faces

In this chapter, we will cover JavaServer Faces (JSF), the standard component framework of the Java EE platform. Java EE 8 includes JSF 2.3, the latest version of JSF. JSF relies a lot on convention over configuration—if we follow JSF conventions then we don't need to write a lot of configuration. In most cases, we don't need to write any configuration at all. This fact, combined with the fact that web.xml has been optional since Java EE 6, means that, in many cases, we can write complete web applications without having to write a single line of XML.

We will cover the following topics in this chapter:

  • Facelets
  • JSF project stages
  • Data validation
  • Named beans
  • Navigation
  • Ajax-enabling JSF applications
  • JSF HTML5 support
  • Faces flows
  • JSF artifact injection
  • JSF WebSocket support
  • JSF component libraries

Introducing JSF

JSF 2.0 introduced a number of enhancements to make JSF application development easier. In the following few sections, we will explore some of these features.

Readers not familiar with earlier versions of JSF may not understand the following few sections completely. Not to worry, everything will be perfectly clear by the end of this chapter.

Facelets

One notable difference between modern versions of JSF and earlier versions is that Facelets is now the preferred view technology. Earlier versions of JSF used Java Server Pages (JSP) as their default view technology. Since the JSP technology predates JSF, sometimes using JSP with JSF felt unnatural or created problems. For example, the JSP lifecycle is different...

Developing our first JSF application

To illustrate basic JSF concepts, we will develop a simple application consisting of two Facelet pages and a single CDI named bean.

Facelets

As we mentioned in this chapter's introduction, the default view technology for JSF 2.0 and newer versions is Facelets. Facelets need to be written using standard XML. The most popular way to develop Facelet pages is to use XHTML in conjunction with JSF-specific XML namespaces. The following example shows how a typical Facelet page looks:

<?xml version='1.0' encoding='UTF-8' ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot...

Custom data validation

In addition to providing standard validators for our use, JSF allows us to create custom validators. This can be done in one of two ways—by creating a custom validator class or by adding validation methods to our named beans.

Creating custom validators

In addition to the standard validators, JSF allows us to create custom validators by creating a Java class implementing the javax.faces.validator.Validator interface.

The following class implements an email validator, which we will use to validate the email text input field in our customer data entry screen:

package net.ensode.glassfishbook.jsfcustomval; 
 
import javax.faces.application.FacesMessage; 
import javax.faces.component.UIComponent; ...

Ajax-enabling JSF applications


JSF allows us to easily implement Ajax (Asynchronous JavaScript and XML) functionality into our web applications by simply employing the <f:ajax> tag and CDI named beans, without needing to implement any JavaScript code or having to parse JSON strings to implement Ajax with JSF.

The following illustrates a typical usage of the <f:ajax> tag:

<?xml version='1.0' encoding='UTF-8' ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:h="http://java.sun.com/jsf/html" 
      xmlns:f="http://java.sun.com/jsf/core"> 
  <h:head> 
    <title>JSF Ajax Demo</title> 
  </h:head> 
  <h:body> 
    <h2>JSF Ajax Demo</h2> 
    <h:form> 
      <h:messages/> 
      <h:panelGrid columns="2"> 
 
        <h:outputText value="Echo input:"/> 
        <h:inputText...

JSF HTML5 support


HTML5 is the latest version of the HTML specification and includes several improvements over the previous version of HTML. Modern versions of JSF include several features to make JSF pages work nicely with HTML5.

HTML5-friendly markup

Through the use of pass-through elements, we can develop our pages using HTML5 and also treat them as JSF components. To do this, we need to specify at least one element attributes using http://xmlns.jcp.org/jsf namespace. The following example demonstrates this approach in action:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:jsf="http://xmlns.jcp.org/jsf">
    <head jsf:id="head">
        <title>JSF Page with HTML5 Markup</title>
        <link jsf:library="css" jsf:name="styles.css" rel="stylesheet"
         type="text/css" href="resources/css/styles.css"/>
    </head>
 <body jsf:id="body">
        <form jsf:prependId="false">
            <table style="border-spacing...

JSF 2.2 Faces flows


JSF 2.2 introduced Faces flows, which defines a scope that can span several pages. Flow scoped beans are created when the user enters a flow (a set of web pages), and are destroyed when the user leaves the flow.

Faces flows adopts the convention over configuration principle of JSF. The following conventions are typically used when developing applications employing faces flows:

  • All pages in the flow must be placed in a directory whose name defines the name of the flow
  • An XML configuration file named after the directory name, and suffixed with -flow, must exist inside the directory that contains the pages in the flow (the file may be empty, but it must exist)
  • The first page in the flow must be named after the directory name that contains the flow
  • The last page in the flow must not be located inside the directory containing the flow and must be named after the directory name and suffixed with -return

The following screenshot illustrates these conventions:

In the preceding example...

Injecting JSF artifacts


The JSF specification predates CDI. As such, many JSF artifacts, such as FacesContext and ExternalContext, had to be obtained via static entry methods; this resulted in hard-to-read boilerplate code. JSF 2.3 introduces the ability to inject JSF artifacts via CDI's @Inject annotation, as seen in the following example:

package net.ensode.javaee8book.jsfarbitrarymess; 
 
import java.io.Serializable; 
import javax.faces.application.FacesMessage; 
import javax.faces.context.FacesContext; 
import javax.faces.view.ViewScoped; 
import javax.inject.Inject; 
import javax.inject.Named; 
 
@Named 
@ViewScoped 
public class ArbitraryMessageController implements Serializable { 
 
    @Inject
    FacesContext facesContext; 
 
    public void saveData() { 
        FacesMessage facesMessage = new  
         FacesMessage(FacesMessage.SEVERITY_INFO, 
         "Data saved successfully", "All Data successfully  
          saved."); 
        facesContext.addMessage(null, facesMessage);...

JSF WebSocket support


In typical web applications, servers always respond to requests from a browser; there is no way for a server to send data to the client browser without responding to a request. WebSocket technology provides full duplex communication between a browser and a server, allowing servers to independently send data to a client, without having to respond to a request. WebSocket technology allows a myriad of new applications to be developed for the web, including updating stock tickers, multiplayer online games, and chat applications.

Note

Although some of these types of web applications were developed before the advent of WebSockets, they relied on hacks to work around the limitations of the HTTP protocol. With WebSockets, these hacks are no longer necessary.

Traditionally, writing applications taking advantage of the WebSocket protocol required a lot of JavaScript code. JSF 2.3 introduces WebSocket support and abstracts out most of the JavaScript plumbing, allowing us to focus...

Additional JSF component libraries


In addition to the standard JSF component libraries, there are a number of third-party JSF tag libraries available. The following table lists some of the most popular:

Tag library

Distributor

License

URL

ICEfaces

ICEsoft

MPL 1.1

http://www.icefaces.org

RichFaces

Red Hat/JBoss

LGPL

http://www.jboss.org/richfaces

Primefaces

Prime Technology

Apache 2.0

http://www.primefaces.org

Summary


In this chapter, we covered how to develop web-based applications using JavaServer Faces, the standard component framework for the Java EE platform. We looked at how to write a simple application by creating pages using Facelets as the view technology and CDI named beans. We also covered how to validate user input by using JSF's standard validators, by creating our own custom validators or by writing validator methods. Additionally, we covered how to customize standard JSF error messages, both the message text and the message style (font, color, and such). Also, we covered how to develop Ajax-enabled JSF pages, as well as how to integrate JSF and HTML5.

Summary

In this chapter, we covered how to develop web-based applications using JavaServer Faces, the standard component framework for the Java EE platform. We looked at how to write a simple application by creating pages using Facelets as the view technology and CDI named beans. We also covered how to validate user input by using JSF's standard validators, by creating our own custom validators or by writing validator methods. Additionally, we covered how to customize standard JSF error messages, both the message text and the message style (font, color, and such). Also, we covered how to develop Ajax-enabled JSF pages, as well as how to integrate JSF and HTML5.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Covers all of the major Java EE 8 APIs and includes new additions such as enhanced Security, JSON-B Processing, and more
  • Learn additional Java EE APIs, such as the Java API for Websocket and the Java Message Service (JMS)
  • Develop applications by taking advantage of the latest versions of CDI, Security, Servlets, and JSF and other Java EE specifications

Description

Java EE is an Enterprise Java standard. Applications written to comply with the Java EE specification do not tie developers to a specific vendor; instead they can be deployed to any Java EE compliant application server. With this book, you’ll get all the tools and techniques you need to build robust and scalable applications in Java EE 8. This book covers all the major Java EE 8 APIs including JSF 2.3, Enterprise JavaBeans (EJB) 3.2, Contexts and Dependency Injection (CDI) 2.0, the Java API for WebSockets, JAX-RS 2.1, Servlet 4.0, and more. The book begins by introducing you to Java EE 8 application development and goes on to cover all the major Java EE 8 APIs. It goes beyond the basics to develop Java EE applications that can be deployed to any Java EE 8 compliant application server. It also introduces advanced topics such as JSON-P and JSON-B, the Java APIs for JSON processing, and the Java API for JSON binding. These topics dive deep, explaining how the two APIs (the Model API and the Streaming API) are used to process JSON data. Moving on, we cover additional Java EE APIs, such as the Java API for Websocket and the Java Message Service (JMS), which allows loosely coupled, asynchronous communication. Further on, you’ll discover ways to secure Java EE applications by taking advantage of the new Java EE Security API. Finally, you’ll learn more about the RESTful web service development using the latest JAX-RS 2.1 specification. You’ll also get to know techniques to develop cloud-ready microservices in Java EE.

Who is this book for?

If you are a Java developer who wants to become proficient with Java EE 8, this book is ideal for you. You are expected to have some experience with Java and to have developed and deployed applications in the past, but you don't need any previous knowledge of Java EE.

What you will learn

  • Develop and deploy Java EE applications
  • Embrace the latest additions to the Contexts and Dependency Injection (CDI) specification to develop Java EE applications
  • Develop web-based applications by utilizing the latest version of JavaServer Faces, JSF 2.3.
  • Understand the steps needed to process JSON data with JSON-P and the new JSON-B Java EE API
  • Implement RESTful web services using the new JAX-RS 2.1 API, which also includes support for Server-Sent Events (SSE) and the new reactive client API

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 12, 2017
Length: 372 pages
Edition : 1st
Language : English
ISBN-13 : 9781788297332
Vendor :
Oracle
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Dec 12, 2017
Length: 372 pages
Edition : 1st
Language : English
ISBN-13 : 9781788297332
Vendor :
Oracle
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just zł20 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just zł20 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 641.97
Java EE 8 and Angular
zł197.99
Architecting Modern Java EE Applications
zł221.99
Java EE 8 Application Development
zł221.99
Total 641.97 Stars icon
Banner background image

Table of Contents

14 Chapters
Introduction to Java EE Chevron down icon Chevron up icon
JavaServer Faces Chevron down icon Chevron up icon
Object Relational Mapping with the Java Persistence API Chevron down icon Chevron up icon
Enterprise JavaBeans Chevron down icon Chevron up icon
Contexts and Dependency Injection Chevron down icon Chevron up icon
JSON Processing with JSON-P and JSON-B Chevron down icon Chevron up icon
WebSocket Chevron down icon Chevron up icon
Java Messaging Service Chevron down icon Chevron up icon
Securing Java EE Applications Chevron down icon Chevron up icon
RESTful Web Services with JAX-RS Chevron down icon Chevron up icon
Microservices Development with Java EE Chevron down icon Chevron up icon
Web Services with JAX-WS Chevron down icon Chevron up icon
Servlet Development and Deployment Chevron down icon Chevron up icon
Configuring and Deploying to GlassFish Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.1
(9 Ratings)
5 star 55.6%
4 star 11.1%
3 star 22.2%
2 star 11.1%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Paulo Diaz Dec 01, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Excelente libro de Aplicaciones basadas en Java para EE
Amazon Verified review Amazon
eva Feb 18, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Es un libro muy completo de Java ee 8. Contiene toda la información que se puede necesitar. Un acierto comprarlo
Amazon Verified review Amazon
Texashowdy Apr 21, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Good summary of the Java EE landscape. The book is a good resource for experienced architects. Examples are focussed and small
Amazon Verified review Amazon
brosnan Jul 06, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Por lo menos lo recibí, demoro un poco pero estoy feliz por ahora tener mi artículo que pedí.
Amazon Verified review Amazon
Elder Moraes Mar 14, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
As usual, David did again a great job on this book. It shows a lot of working code exploring deep details of Java EE 8 API's and also giving plenty concepts that will help you understand its basis.If you are a Java EE developer or want to become one, this book is surely a must.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.