Skip to main content
main-content

Über dieses Buch

Learn and master the new features in the JSF 2.3 MVC web framework in this definitive guide written by two of the JavaServer Faces (JSF) specification leads. The authors take you through real-world examples that demonstrate how these new features are used with other APIs in Java EE 8. You’ll see the new and exciting ways JSF applications can use to communicate between a client and a server, such as using WebSockets, invoking bean methods directly from Ajax, executing client-side JavaScript when Ajax calls complete, and more
Along the way you’ll broaden your knowledge of JSF components and web APIs best practices, and learn a great deal about the internals of JSF and the design decisions that have been made when building the JSF API. For example, you’ll see what artefacts are now CDI injectable, how CDI changed JSF internally, and what some of the caveats are when working with the CDI versions of a JSF artefact.
Furthermore, you'll build an example application from scratch. After reading The Definitive Guide to JSF in Java EE 8, you'll be ready to build your own efficient and secure web applications.

What You Will LearnLeverage the new features in JSF 2.3 in your existing applications
Integrate JSF and CDI
Use the brand new Component Search Expression framework, which enables you to more easily locate components from your template
Extend the Component Search Expression framework with your own search operators
Work with the different ways of mapping requests to JSF, make your application use extensionless URLs, and programmatically inspect which resources are present in your application
Master the best practices for web application development and see which are obsolete

Who This Book Is For
Existing JSF or Java developers who need to create a web UI. No prior knowledge of JSF is required, but the book does skew towards the more experienced developer. Concepts such as dependency injection and MVC are assumed to be known, as is a general knowledge about HTML, HTTP and other web standards.

Inhaltsverzeichnis

Frontmatter

Chapter 1. History

Abstract
This chapter describes the history of JSF, starting from its early conception and ending where we are today at the moment of writing. We’ll discuss how the JSF API (application programming interface) itself evolved, which important events took place during that evolution, and who some of the people were that were involved in all of this.
Bauke Scholtz, Arjan Tijms

Chapter 2. From Zero to Hello World

Abstract
In this chapter you will learn how to set up a JSF (JavaServer Faces) development environment with the Eclipse IDE (integrated development environment), the Payara application server, and H2 database from scratch.
Bauke Scholtz, Arjan Tijms

Chapter 3. Components

Abstract
JSF (JavaServer Faces) is a component-based MVC (Model-View-Controller) framework. In essence, JSF parses the view definition into a “component tree.” The root of this tree is represented by the “view root” instance associated with the current instance of the faces context.
Bauke Scholtz, Arjan Tijms

Chapter 4. Form Components

Abstract
These are the most important components of the standard JSF (JavaServer Faces) component set. Without them, JSF wouldn’t have been very useful in the first place. When using plain HTML elements instead of JSF components, you’d end up polluting the controller with code to manually apply, convert, and validate submitted values; to update the model with those values; and to figure out the action method to be invoked. That’s exactly the hard work JSF should take off your hands as being a component-based MVC (Model-View-Controller) framework for HTML form-based web applications.
Bauke Scholtz, Arjan Tijms

Chapter 5. Conversion and Validation

Abstract
At its core, JSF (JavaServer Faces) as an HTML form-based MVC (Model-View-Controller) framework basically needs to convert between Java objects (entities, beans, value objects, data transfer objects, and what not) and character sequences (strings) all the time. The HTTP request is basically broken down into plain vanilla strings representing headers and parameters, not as Java objects. The HTTP response is basically written as one big sequence of characters representing HTML or XML, not as some sort of serialized form of a Java object. However, the average Java model behind a JSF page doesn’t necessarily contain String properties over all place. That would defeat the strong typed nature of Java. This is where Converters come into the picture: converting between objects in model and strings in view.
Bauke Scholtz, Arjan Tijms

Chapter 6. Output Components

Abstract
Technically, the input components as described in Chapter 4 are also output components. They are not only capable of processing any submitted input values but also capable of outputting the model value during the render response phase (sixth phase). This is also visible in the JSF (JavaServer Faces) API (application programming interface): the UIInput superclass extends from the UIOutput superclass.
Bauke Scholtz, Arjan Tijms

Chapter 7. Facelets Templating

Abstract
When JSF (JavaServer Faces) came out for first time in 2004, only JSP (Java Server Pages) had view technology. It was immediately clear that it was an ill-suited view technology for web development with JSF. The problem with JSP is that it writes to the HTTP response as soon as it encounters template text, while JSF would like to first create a component tree based on the view declaration in order to be able to perform the life cycle processing on it.
Bauke Scholtz, Arjan Tijms

Chapter 8. Backing Beans

Abstract
The “backing bean” is a JSF-specific concept. It represents the sole JavaBean class which is ultimately used as a “managed bean” responsible for providing data, actions, and/or UI (user interface) components in a JSF page.
Bauke Scholtz, Arjan Tijms

Chapter 9. Exception Handling

Abstract
Sometimes things can unexpectedly go wrong. In Java, that usually manifests as an Exception being thrown. In Java EE, it’s basically no different. The issue is how and when to properly handle them. By default, any uncaught exception during an HTTP request will end up in a default error page provided by the application server.
Bauke Scholtz, Arjan Tijms

Chapter 10. WebSocket Push

Abstract
JSF 1.0 introduced HTML form-based POST action support. JSF 2.0 introduced AJAX-based POST support. JSF 2.0 introduced GET query string parameter mapping support. JSF 2.2 introduced GET-based action support. JSF 2.3 introduces WebSocket support.
Bauke Scholtz, Arjan Tijms

Chapter 11. Custom Components

Abstract
In Chapter 7 you should have learned that Facelet templates as in <ui:composition>, <ui:include>, and <ui:decorate> are useful when you want to split main page layout fragments into reusable templates, such as header, menu, main content, and footer. And that Facelet tag files such as <t:field> are useful when you want to have a reusable group of components in order to minimize code duplication. And that composite components such as <t:inputLocalTime> are useful when you want to create a custom component with a single responsibility based on existing components and, if necessary, a bunch of HTML.
Bauke Scholtz, Arjan Tijms

Chapter 12. Search Expressions

Abstract
As stated in the sections “Ajax Life Cycle” in Chapter 3 and “Ajaxifying Components” in Chapter 4, the execute and render attributes of <f:ajax> tag take a space-separated collection of so-called component search expressions
Bauke Scholtz, Arjan Tijms

Chapter 13. Security

Abstract
Security for web applications is a broad field and includes a number of topics such as protecting access to resources, shielding against injection attacks of various kinds, and preventing users from being tricked into doing malicious actions on behalf of an attacker.
Bauke Scholtz, Arjan Tijms

Chapter 14. Localization

Abstract
JSF has always had decent internationalization support. Since JSF 1.0 you can supply java.util.ResourceBundle-based bundle files in different locales, which in turn get dynamically included as text in the web page at the declared places. Also, all JSF converters and validators have their own set of localized default messages which you can easily customize via a message bundle or, since JSF 1.2, via new requiredMessage, converterMessage, and validatorMessage attributes. JSF 2.0 adds, via the new javax.faces.application.ResourceHandler, API (application programing interface) support for localizable assets such as stylesheets, scripts, and images.
Bauke Scholtz, Arjan Tijms

Chapter 15. Extensions

Abstract
If there is one single element or virtue of JSF (JavaServer Faces) to which we can attribute its lasting for so long, it’s probably its ability to be extended in a large variety of ways. From the onset JSF made it possibly to have most of its core elements replaced, decorated, or augmented.
Bauke Scholtz, Arjan Tijms

Backmatter

Weitere Informationen

Premium Partner

    Bildnachweise