Showing posts with label JSF. Show all posts
Showing posts with label JSF. Show all posts

Wednesday, November 25, 2015

Book Review: Digital Java EE 7 Web Application Development

Packt Publishing recently (September 2015) published Peter Pilgrim's Digital Java EE 7 Web Application Development with the subtitle "Develop Java enterprise applications to meet the emerging digital standards using Java EE 7." Digital Java EE 7 Web Application Development contains 9 chapters and 4 appendices spanning over 400 pages. The book's subtitle is "Develop Java enterprise applications to meet the emerging digital standards using Java EE 7."

Preface

The Preface of Digital Java EE 7 Web Application Development states that the book is "a continuation of the first book Java EE 7 Developer Handbook" with Digital Java EE 7 Web Application Development focusing on "the Java presentation tier." The Preface adds that "the book was written for the developers who want to become superior and adept at building a web application on JVM with the standard Java EE 7 platform" and with specific focus on JavaServer Faces with some coverage of JavaScript and AngularJS.

The Preface contains short summaries (2-3 sentences each) of each of the book's chapters and appendices. It also lists the software necessary to run the examples provided in the book: Java 8, GlassFish 4.1, Gradle 2.6, Chrome DevTools, Firefox Developer Tools, "Chris Pederick's Web Developer and User Agent Switcher extensions", and "a decent Java Editor or IDE for coding."

In describing "who this book is for," the Preface of Digital Java EE 7 Web Application Development states, "this book is pitched at intermediate Java developers" with "a good command over the programming language" that includes Java SE knowledge of "classes, inheritance, and Java Collections" and Java EE knowledge of "Java persistence, Java servlets, and deployment of the WAR files to an application server."

Chapter 1: Digital Java EE 7

The initial chapter of Digital Java EE 7 Web Application Development begins with a high-level introduction to working in the digital domain and looks at how Java fits inside the digital domain. There is specific focus on recent changes in Java 8 including removal of PermGen, introduction of the G1 garbage collector and introductory code listing and explanatory text related to lambda expressions.

Chapter 1 also looks at JavaScript with specific focus on JavaScript libraries such as jQuery, AngularJS, and GruntJS. The chapter provides a brief overview of Java EE 7 features that are applicable in the digital design world and introduces application servers that implement Java EE 7 including GlassFish 4.1, Payara Server, and WildFly. There is also a brief introduction (with code listing) to JavaServer Faces.

Chapter 2: JavaServer Faces Lifecycle

JavaServer Faces (JSF) is the exclusive topic of Chapter 2 of Digital Java EE 7 Web Application Development. The chapter introduces JavaServer Faces with a historical perspective and references terminology such as responsive design, mobile web design, Digital by Default, and Default to Open. A brief history of JSF is outlined and some key new features of JSF 2.2 are listed. Arguments for choosing JSF over other Java-based web frameworks are also made and mostly center around JSF being a standard.

The second chapter introduces Model-View-Controller (MVC) and describes how JSF implements MVC. The chapter provides a high-level overview of Facelets and looks at the JSF request processing lifecycle. The chapter provides multiple JSF code listings and demonstrates JSF features such as JSF annotations, expression language, web descriptor, and JSF XML namespaces. After providing another JSF code example, Chapter 2 returns to more in-depth coverage of expression language.

Chapter 3: Building JSF Forms

Like the second chapter, Digital Java EE 7 Web Application Development's third chapter is JSF-centric, but does include some HTML5/CSS/Bootstrap code in the example that is built throughout the chapter. This chapter begins with an example of implementing a CRUD-oriented application using a JSF Facelet with Bootstrap via passthrough. Several JSF tags and tag libraries are introduced as they are applied in the example being built up in Chapter 3. The example constructed in Chapter 3 also demonstrates use of Java Persistence API (JPA) as functionality to allow contacts to be created, read, updated, and deleted is added.

One of the things that can be confusing to someone new to JavaServer Faces is the difference between the older JSF managed beans and the newer CDI-based beans. The third chapter concludes with a discussion that addresses this.

Chapter 4: JSF Validation and AJAX

The fourth chapter of Digital Java EE 7 Web Application Development begins with an explanation of why validation is important in web applications and then introduces and contrasts server-side validation with client-side validation. The chapter then details using the h:message and h:messages JSF tags to display errors.

Chapter 4's coverage of validation in JSF introduces "two main ways of achieving validation": Java EE 7's Bean Validation 1.1 and "traditional" JSF validation. The chapter provides a code example, a table of relevant annotations, and explanatory text in its introduction of bean validation. Explanatory text and code listings are also provided in the introduction to JSF validation.

This fourth chapter also introduces applying the attributes requiredMessage, validatorMessage, and conversionMessage for custom messages. The chapter looks at overriding validation messages globally via properties files and demonstrates adding a custom validation method to a rendering tag.

The section of Chapter 4 on custom validators demonstrates creating a custom validator by writing a class that implements javax.faces.validator.Validator and annotating it with @javax.faces.validator.FacesValidator. The "Converters" section of Chapter 4 describes converters as "JSF classes that convert between strings and objects" and then provides detailed discussion and code examples implementing a custom converter.

Chapter 4 also looks at "validating immediately with AJAX." This section introduces Ajax and JSF's "built-in support for AJAX requests and responses." It introduces <f:ajax>, provides multiple code listings demonstrating use of it, provides a table of its attributes, and looks at how it relates to the JSF lifecycle.

One of Chapter 4's major sections is "Handling views" and this concluding section of the chapter covers invoking and passing parameters to controller methods, invoking an action event listener, redirecting pages, and debugging JSF with <ui:debug>.

Chapter 5: Conversations and Journeys

Chapter 5 of Digital Java EE 7 Web Application Development focuses on "JSF conversation scope." The chapter begins by looking at how JSF integrates Context and Dependency Injection (CDI) context and dependency injection. The chapter defines "conversational scope" as "defined by a lifecycle that spans many HTTP requests to the server." The @javax.enterprise.context.ConversationScoped annotation and the CDI-injected javax.enterprise.context.Conversation interface are introduced and demonstrated early in this chapter before coverage of the lifecycle of a conversation scoped bean.

There are several screen snapshots and code listings in this chapter. These payday loan application examples include application of Bootstrap CSS and JSF 2.2's support for HTML5-friendly pages with new namespace http://xmlns.jcp.org/jsf. They illustrate applying Ajax, jQuery, and the HTML5 Range element.

The final major section of the fifth chapter covers JSF custom components. An example of a custom component implemented with an XHTML-defined Facelet view backed by a backing bean is provided. Another portion of this section introduces the JSF 2.2 ability to "generate the custom tag without specifying any XML declaration."

Chapter 6: JSF Flows and Finesse

Digital Java EE 7 Web Application Development's sixth chapter emphasizes what I think may be the most interesting feature of JSF 2.2: Faces Flows. The chapter begins by explaining the use cases and sample applications that inspired and can make most use of Faces Flow before delineating some key characteristics of Faces Flow. Several early sections use code listings to demonstrate use of annotations (such as @javax.faces.flow.FlowScoped) and other Faces Flow concepts in simple flows.

Chapter 6 demonstrates use of the <error-page> element to declare "an association between an exception type and a page view" that allows for nicer presentation of the "one of the most notorious exceptions" encountered in JSF-based applications (javax.faces.application.ViewExpiredException).

The sixth chapter also looks at complex flows. It demonstrates and describes flows that switch on different cases (conditional) and nest flows. In addition to the inline explanatory examples, the chapter includes a "a real-world example" with significant discussion on security-related aspects.

Faces Flows is not the only JSF 2.2 feature covered in Chapter 6. The chapter also introduces Resource Library Contracts. Several nuances are demonstrated with code listings and there is a section on using Resource Library Contracts in conjunction with Faces Flows. The chapter concludes with a bullet list of tips for using Faces Flows.

Chapter 7: Progressive JavaScript Frameworks and Modules

Chapter 7 of Digital Java EE 7 Web Application Development begins with the observation that "in the contemporary way of building a website, there is no escape from the language of JavaScript because it is a de facto standard of modern web browsers." Although earlier chapters touched on JavaScript and related technologies, this is the first chapter that focuses on something other than JSF. The focus of the chapter is JavaScript and JavaScript libraries and frameworks.

The seventh chapter begins with an introduction to the basics of JavaScript. After covering some of the basics and gotchas of JavaScript and introducing some JavaScript features in comparison to similar Java features, the chapter moves onto introducing jQuery (and sizzle) in more detail. Along with demonstrating use of jQuery for DOM manipulation and simple animation, the chapter also demonstrates including jQuery code in a JSF application.

RequireJS, Underscore, and Grunt are also introduced in Chapter 7. There are several pages devoted to each that introduce some key features and uses of each framework.

Chapter 8: AngularJS and Java RESTful Services

The eighth chapter of Digital Java EE 7 Web Application Development shifts from JSF to an "alternate design mode." I like the author's articulation (probably because it coincides with my own observations) of where JSF fits best and where this alternate design mode fits best. Pilgrim writes:

The design philosophy behind building an application on a single page such that it resembles a desktop application is in marked contrast to the JavaServer Faces' original design of navigation links between pages. ... JSF lends itself to applications that are extremely stateful in nature and design, where the customer journey is based on page-to-page navigation.

After successfully explaining why JSF in not a good fit for the single-page design model, the author lists some advantages and disadvantages of the single-page model. An example of a single-page application for this chapter is introduced and is related to managing case worker information. This example is defined in more detail after the AngularJS coverage.

Chapter 8 introduces one of the trendiest and most popular web development frameworks in AngularJS. The introduction is fairly thorough for only being part of a single chapter. Significantly more details of AngularJS are illustrated with a return to the caseworker application implemented with AngularJS. The casework sample application demonstrates use of Java EE features such as JPA, REST-based web services with JAX-RS, and WebSocket in addition to AngularJS.

Chapter 9: Java EE MVC Framework

The final chapter of Digital Java EE 7 Web Application Development is a future-looking chapter that looks past Java EE 7 and introduces the JSR 371: Model-View-Controller (MVC 1.0) Specification. The chapter explains why this specification is being planned for Java EE 8 and also introduces a reference implementation of it (Ozark). Because Java EE 8 (JSR 366) is still forthcoming, Pilgrim warns the reader of this chapter, "the information here is subject to change because MVC is evolving."

This ninth chapter introduces the new package called javax.mvc and the @javax.mvc.Controller annotation. The chapter then explains and illustrates applying MVC 1.0 with JAX-RS annotations. The examples and explanations also cover using JSF for the view portion and using the javax.mvc.Models interface for the model portion of an MVC 1.0-based application.

Chapter 9 introduces JavaScript-based Handlebars.js (and Mustache) and then segues from there into an introduction of the Java port of this. Several pages are devoted to building up the example of the application using Ozark and Handlebars for Java.

The final chapter concludes with a look at a couple ways in which the Java MVC 1.0 specification might still change and with a discussion of design considerations when using Java MVC.

The Appendices

Appendix A ("JSF with HTML5, Resources, and Faces Flows") is a "quick reference" on the JSF library. The first part of this appendix is a standard library reference with emphasis on Java EE 6 (JSF 2.0) and Java EE 7 (JSF 2.2) versions of JavaServer Faces. The second part covers Faces Flows with a thorough reference.

Appendix B ("From Request to Response") covers common topics associated with a web application's architecture. These topics include HTTP (protocol itself, advancements, request methods and response codes), standard Java EE web architecture (servlet + CDI + EJB), extended Java EE web architectures (NoSQL, Model-View-ViewModel, Java Temporary Caching, embedded server/containerless system, microservices), and brief discussion addressing the question, "Is it important to be known as a full stack developer?"

Appendix C ("Agile Performance – Working inside Digital Teams") consists on ten pages that look at structure of agile digital development teams and roles on those teams.

Appendix D ("Curated References") is over six pages of "references around the digital software development" that are categorized "into concepts and themes" of "Service delivery", "Agile and leadership", "Architecture", "User interface", and "Java EE and JVM technology." Because these references include URLs, it is easy to click on these in the electronic versions to be taken directly to the referenced resource.

What is Digital Java EE 7 Web Application Development and Who Is It Best Suited For?

One of the most valuable insights I believe I can provide to someone trying to decide whether to purchase or borrow this book is to articulate what this book covers and who it is best suited for. I attempt that here.

  • Digital Java EE 7 Web Application Development provides significant coverage of JavaServer Faces (JSF).
    • Chapters 2 through 6 are almost exclusively JSF-focused and JSF has significant presence in Chapter 1 and Chapter 9.
    • It's not just JSF, however, and covers using HTML5 and related popular frameworks and libraries with JSF.
    • Chapter 8 (single-page applications with AngularJS) is not JSF at all.
  • Digital Java EE 7 Web Application Development focuses on newer JSF features.
    • As its title implies, the focus of this book is on Java EE 7 and JSF 2.2 with some mention of Java EE 6 (JSF 2.0).
    • This is probably NOT the book you want to get to learn JSF for the first time, but rather is more suited for someone with minimal JSF experience through JSF 2.0 who wants to learn what's available in JSF 2.2 and Java EE 7.
  • Digital Java EE 7 Web Application Development provides broad coverage of developing Java EE 7 web application user interfaces.
  • Digital Java EE 7 Web Application Development is most likely to appeal to these types of developers:
    • Intermediate-level (or advanced) Java developers (as described in the book's preface) who have only basic familiarity with JSF and want to learn more about newer (Java EE 7/JSF 2.2) JSF features.
    • Java developers with only limited awareness of modern web client technologies and frameworks who want to learn how to use JSF with HTML5 and related technologies.
    • Java developers who want a broad view of the currently favored and standard Java EE 7 technologies for web development and want an introductory chapter on Java EE MVC coming with Java EE 8.
  • Digital Java EE 7 Web Application Development may not meet expectations of these types of developers:
    • Developers looking for an introduction to JavaServer Faces; this book is better suited to developers with at least minimal JSF experience as it's not an introductory book and it mostly focused on newer JSF features.
    • Developers looking for a reference on HTML5, JavaScript, CSS or related frameworks and libraries such as AngularJS, jQuery, and Bootstrap; although this book does introduce using these technologies with JSF, the coverage of these particular technologies is mostly introductory.
    • Developers looking for a book on developing Java-based web applications with JAX-WS (SOAP/WSDL-based web services), Java servlets, or one of the many available non-standard Java/JVM web frameworks; this book does not cover these older and/or non-standard technologies and instead focuses it coverage on JSF 2.2 and JAX-RS.

Other General Observations

The following are some general observations and opinions of mine formed while reading the PDF version of Digital Java EE 7 Web Application Development provided to me by Packt Publishing.

  • Digital Java EE 7 Web Application Development includes numerous code examples
    • Code listings tend to build upon same simple example applications that highlight benefits and advantages of the approach being demonstrated.
    • Code listings are black font on white background with no color syntax highlighting and no line numbers even in the electronic (PDF) version of the book that I read.
    • I liked that there are extensive code listings and understand that printed books would not be able to have color syntax highlighting, but having color syntax in the code examples (especially the larger ones) or otherwise emphasized code would have helped with code readability.
    • I recommend acquiring code listings in Pilgrim's GitHub repository so that an IDE or text editor can be used to view the code.
  • There are several color screen snapshots in the PDF version of Digital Java EE 7 Web Application Development to help illustrate the web pages rendered by JSF and related web technologies. There are also color graphics for illustrating concepts in the electronic version.
  • Although Digital Java EE 7 Web Application Development is a Java EE book, it does a nice job of inserting some Java SE 7 JDK libraries in the examples. In particular, the Java 8 date/time library is used multiple times and Chapter 1 introduces lambda expressions.
  • For the most part, Digital Java EE 7 Web Application Development reads fairly well. However, as with several other Packt Publishing titles I have reviewed, it could have used more editing. There are several typos in Digital Java EE 7 Web Application Development, but these rarely prevent the content from being understood. To help convey the type of typos for you to judge how they might impact your ability to understand what is being communicated, I include some examples here:
    • "SERVERITY_WARNING"
    • "these tags render the content from the javax.faces.HtmlMessages and javax.faces.HtmlMessages components respectively"
    • "The JavaScript support functions as a first-class citizen and rules on a and supports the declaration of functions..."
    • "JSF 1.0 was created in the early noughties,..."
    • "...new package structure reserved for MVC under javax.mvc. The @javac.mvc.Controller annotation..."
  • Each of the chapters has a set of questions and exercises at the end of the chapter. I didn't run through any of these and cannot comment on the benefits of them. I also am not aware of any answers or solutions being provided for any of the exercises or questions.
  • Pilgrim references his other Packt title, Java EE 7 Developer Handbook, several times in this book for readers who need additional background Java EE details, particularly in areas outside of the user interface.
    • Reviews for the earlier book probably provide good indicators of what one can expect from Digital Java EE 7 Web Application Development. Indeed, I noticed that several of the positive and negative comments on Amazon.com apply to the book I'm reviewing as well. As of this writing, there are 10 reviews of Java EE 7 Developer Handbook on Amazon.com with an average 3.8 (out of 5) rating.
  • Find the author's own description of his book in the blog post My Digital Java EE 7 book is now published.

Conclusion

Digital Java EE 7 Web Application Development provides a survey of the most popular Java EE 7 approaches for developing web applications. JavaServer Faces receives the lion's share of the discussion with focus particularly on Java EE 7's version of JSF (2.2). Digital Java EE 7 Web Application Development introduces JavaScript and AngularJS and discusses using HTML5 technologies, libraries, and frameworks with JSF. There is also forward-looking chapter on Java EE 8's forthcoming Java EE MVC. Digital Java EE 7 Web Application Development is a book largely on modern JSF, but it's not accurate to say it's only a JSF book and it's probably not the best introductory book for those who have never used JSF. Instead, this book is best suited for Java developers with some awareness of JSF, but who want to learn more about JSF 2.2 and integrating JSF with other non-Java web languages, libraries, and frameworks.

Monday, December 22, 2014

Book Review: Mastering JavaServer Faces 2.2

Anghel Leonard's Mastering JavaServer Faces 2.2 (Packt Publishing, 2014) has the subtitle, "Master the art of implementing user interfaces with JSF 2.2." The book features twelve chapters and a short appendix spanning approximately 530 substantive pages. This blog post is my review of the PDF version of the book.

Preface

The Preface of Mastering JavaServer Faces 2.2 provides 2 to 3 sentences summarizing each of the book's chapters. It also recommends NetBeans 8+, GlassFish 4, and Mojarra JavaServer Faces 2.2.6 for running the book's sample applications. The "Who this book is for" section of the Preface clearly articulates that Mastering JavaServer Faces 2.2 is intended for readers who are already familiar with JavaServer Faces. This section states:

This book is a perfect symbiosis between JSF 2.0 and 2.2. It is dedicated to JSF developers who have previous experience and want to upgrade their knowledge to the new JSF 2.2. By fortifying your knowledge on JSF 2.0 and adding the power of JSF 2.2, you will soon become a JSF expert.

I re-emphasize this point here: Mastering JavaServer Faces 2.2 assumes JavaServer Faces experience. The book dives right into newer (JSF 2.2) JavaServer Features without the traditional background and introductory text one would expect from a book that introduces a language or framework. In other words, this book would be best suited for a developer with JSF experience who wants to learn about JSF 2 and JSF 2.2 new features or who has an older book on earlier versions of JSF and wants to use this book as a companion to that older book.

Chapter 1: Dynamic Access to JSF Application Data through Expression Language (EL 3.0)

The initial chapter of Mastering JavaServer Faces 2.2 begins fast with an introduction to Expression Language (EL). The chapter looks at EL 3.0 (JSR 341) syntax (operators, reserved words, immediate evaluation with ${}, deferred evaluation with #{}, referencing both CDI managed beans and JSF managed beans, referencing managed beans' properties and nested properties and methods, referencing Java enumerated types, accessing collections from JSF, and implicit objects).

I liked the Chapter 1 section on "writing a custom EL resolver" because I was not previously aware that one could write one's own custom implicit variables in JSF expression language. This section introduces EL Resolvers, demonstrates how to writ a custom EL Resolver, and describes how to differentiate between a VariableResolver and a PropertyResolver.

The "EL 3.0 overview" section of the first chapter introduces EL 3.0 (part of Java EE 7), lists some of its features, and describes how to use it with JSF. One of the more interesting portions of this section for me was the coverage of EL lambda expressions and streams.

Chapter 2: Communication in JSF

The second chapter of Mastering JavaServer Faces 2.2 opens with the statement, "Communication is the core of a JSF application, and is one of the main aspects that dictate the architecture of such an application." It adds, "JSF provides many solutions for ensuring a powerful and flexible communication layer between JSF components and also between JSF and XHTML pages, the JavaScript code, and other third-party components." With this introduction, the chapter moves onto covering a lengthy list of miscellaneous approaches to communicating between components of a JSF application.

The topics covered in Chapter 2 include context parameters, <f:param ...> tag and >c:set<, view parameters (UIViewParameter/<f:viewParam>), GET request view actions (<f:viewAction>), <f:attribute> tag (demonstrated with an example that modifies supported behavior of a PrimeFaces component), action listeners (<f:setPropertyActionListener>), JSF Flash scope, cookies, hidden fields (<h:inputHidden>), accepting passwords (<h:inputSecret>), accessing JSF user interface components from JSF Java code, EL method expressions, JSF data binding, injecting one managed bean into another managed bean (@ManagedProperty), and communication between managed beans.

Chapter 3: JSF Scopes – Lifespan and Use in Managed Beans Communication

Chapter 3 of Mastering JavaServer Faces 2.2 is all about scopes in JavaServer Faces. The chapter contrasts JSF managed beans and CDI beans and recommends "[using] CDI beans whenever possible," but does discuss situations in which JSF managed beans are preferable. This section includes a useful figure that makes it easy to see the JSF core scope annotations (javax.faces.bean) alongside the CDI scope annotations (javax.enterprise.context). The section describes each level of scope in a JSF application (request, session, view, application, conversation, flow, dependent pseudo-scope, none, custom) and whether JSF managed beans and/or CDI beans support each scope. This coverage of scopes includes code listings for each type of bean to which that scope applies. The sections on flow scope and custom scopoe are longer than the others and particularly useful in understanding these relatively more complicated scopes.

The third chapter concludes with brief sections on easy and lazy managed bean instantiation, allowable scopes for injected and injecting managed beans, and when to use @ManagedProperty versus @Inject. There are several useful figures in this chapter that use shapes and colors to illustrate points being made.

Chapter 4: JSF Configurations Using XML Files and Annotations – Part 1

Mastering JavaServer Faces 2.2's fourth chapter looks at how JSF 2.2 allows annotations to be used to configure many characteristics of a JSF application that formerly had to be configured in a faces-config.xml file. A table that is present early in this chapter maps old ("Before JSF 2.2") namespaces to new ("JSF 2.2") namespaces. The chapter also looks at specifying certain JSF characteristics both with XML and programmatically. The chapter has sections explaining how to use and order multiple configuration files and how to support internationalization by configuring locales and resource bundles.

Chapter 4 has a lengthy section on "configuring validators and converters." I like the author's discussion in this section regarding the state of injecting dependencies into validators and whether it's supported in JSF 2.2 or 2.3. Configuring JSF application navigation in another large topic in the fourth chapter that covers implicit navigation, conditional navigation, preemptive navigation (AKA predetermined navigation), and programmatic navigation.

Chapter 4's focus on configuration moves onto configuring action listeners, system event listeners, phase listeners, @ListenerFor and @ListenersFor.

Chapter 5: JSF Configurations Using XML Files and Annotations – Part 2

The fifth chapter of Mastering JavaServer Faces 2.2 continues the general theme of JSF configuration that the preceding chapter also addressed. The chapter begins with a relatively in-depth look at various approaches for configuring resource handlers (default configuration via placement in JSF 2.0 conventional locations, custom resource handler, and javax.faces.WEBAPP_RESOURCES_DIRECTORY JSF 2.0 context parameter in web.xml file). The section in Chapter 5 on configuring view handlers discusses and demonstrates writing custom view handlers to "convert absolute URLs into relative URLs" and to handle encountered ViewExpiredExceptions.

Chapter 5's section on overriding JSF renderers uses code listings and explanations to demonstrate overriding the HTML output by JSF components when rendered. I particularly liked the "little bit tricky" example of extending ResponseWriterWrapper to change the behavior of writeText to write escaped strings and making some other changes to support that PrimeFaces-like functionality in standard JSF. Another section in the chapter looks at extending ClientBehaviorBase and the other steps necessary to "define specific client-side behavior to a component in a reusable approach."

A considerable portion of Chapter 5 is devoted to JSF factories. Examples include configuring the global exception handler by extending ExceptionHandlerFactory and ExceptionHandlerWrapper, configuring the RenderKitFactory, configuring PartialViewContext, configuring VisitContext, configuring ExternalContext, and configuring Flash by extending FlashFactory and FlashWrapper. Each of these is explained by spelling out the steps needed to perform the configuration and then demonstrating those steps implemented with code listings.

Chapter 5 concludes with coverage of enabling and disabling the ClientWindow API, configuring the JSF lifecycle by extending LifecycleFactory and LifecycleWrapper, configuring an application by extending ApplicationFactory and ApplicationWrapper, and configuring View Declaration Language (VDL), and using more than one configured factory in conjunction with each other to write "a Java Servlet capable of converting a non-JSF request into a JSF view."

Chapter 6: Working with Tabular Data

Chapter 6 is devoted to coverage of applying <h:dataTable> to represent tabular data in JSF. Specific examples covered include rendering of tabular data from JSF-hosted POJOs, displaying a collection of objects with CollectionDataModel, presenting sorted data, an introduction to DataModel, deleting a row from a table, modifying a row in a table, adding a new row, supporting selection of a single row and multiple rows, nesting tables, paginating tables, filtering tables, and styling tables.

The sixth chapter also demonstrates how to generate a JSF table programatically with JSF API classes such as HtmlDataTable, HtmlColumn, and HtmlOutputText.

Chapter 7: JSF and AJAX

The seventh chapter of Mastering JavaServer Faces 2.2 covers use of JavaServer Faces with Ajax. The chapter introduces <f:ajax> and the JSF/Ajax lifecycle. It then provides detailed explanations of the main attributes of <f:ajax>: execute, render, listener, event, onevent, onerror.

Mastering JavaServer Faces 2.2's Chapter 7 covers more examples of using JSF with Ajax such as grouping multiple components within a single <f:ajax> tag, "updating input fields with Ajax after validation error" using resetValues, implementing Cancel and Clear buttons, mixing Ajax and Flow scope, determining if a request is an Ajax request (PartialViewContext.isAjaxRequest or headers Faces-Request and X-Requested-With), using <f:param> with <f:ajax>, controlling client-side Ajax queuing with <f:ajax>'s delay attribute, explicitly loading and customizing the JavaScript file that contains JSF's Ajax support (jsf.js).

Chapter 8: JSF 2.2 – HTML5 and Upload

Chapter 8 is introduced as being primarily composed of two sections: "The first part will present the JSF 2.2 support for HTML5, while the second part discusses the new upload component of JSF 2.2." The chapter's section on using HTML5 with JSF 2.2 discusses pass-through attributes and pass-through elements (TagDecorator). It also discusses application of Bean Validation 1.1 with HTML5 and JSF 2.2.

The section of Chapter 8 on JSF Upload introduces <h:inputFile> and some of its "most important" attributes before discussing use of multiple upload tags, identify characteristics of a file to be uploaded, writing uploaded data to disk, building a file upload validator, using upload with Ajax, uploading multiple files, upload with both indeterminate and determinate progress bars, and an especially lengthy discussion on providing previews of images to be uploaded.

Chapter 9: JSF State Management

The ninth chapter of Mastering JavaServer Faces 2.2 states early in the chapter that "JSF saves and restores the view state between requests using the ViewHandler/StateManager API. ... JSF uses this technique because it needs to preserve the views state over the HTTP protocol, which is a stateless protocol." The chapter goes on to explain how JSF 2.0 and 2.2 have improved JSF application performance with changes in how JSF state is managed. It provides a very detailed example of persisting state in JSF Mojarra to a MongoDB database.

One of the more interesting discussions in the ninth chapter for me was the discussion on JSF 2.2 support for stateless views via the transient attribute on the <f:view> element. Another interesting discussion covers security in JSF (CSRF, XSS, and SQL injection).

Chapter 10: JSF Custom Components

The opening statement of Chapter 10 is, "JSF is a component-based framework, and JSF custom components are the major proof that sustain JSF flexibility and extensibility." The chapter differentiates between custom components and composite components. I like the author's recommendation to look for already existing components as the first step when deciding to implement and then implement a custom component. This idea and a few other ideas are presented as possibly more appropriate approaches than implementing a custom component in many situations.

Chapter 10 explains and demonstrates "building noncomposite custom components" in JSF 2.2 with a single Java class annotated with @FacesComponent. The explanation and demonstration of writing noncomposite custom components dives into deeper details about implementing more complex custom components with Java classes and tag handlers.

Chapter 10's coverage of "building composite components" describes JSF 2 custom components as "practically custom components written in XHTML pages using markup tags" and is a longer and more detailed section than the section on noncomposite custom components. The author makes a good point here that use of XHTML "means that JSF page authors can start writing their components without having the same level of knowledge and skills as dedicated JSF component authors." This section demonstrates implementation of an example of a composite component that makes it easy to compare to the same example application implemented earlier in the chapter with a noncomposite custom component. Chapter 10 also provides explanations and illustrations of transforming the jQuery UI range slider component into a JSF composite component and transforming the HTML5 DatePicker into a JSF composite component.

There are several aspects of developing composite components in JSF covered in Chapter 10. These include working with composite facets, validating and converting input information within a composite component, distributing a composite component as a JAR, and instantiating composite components programatically.

Chapter 11: JSF 2.2 Resource Library Contracts – Themes

The second-to-last chapter of Mastering JavaServer Faces 2.2 starts with the sentence, "Starting with version 2.0, JSF developers exploit Facelets as the default View Declaration Language (VDL)." The early part of this chapter also describes a Facelet template as "a mix of XHTML and other resources such as CSS, JS, and images" that "acts as a base (or a model) for the application pages," providing "reusable code that serves as a consistent and standard look and feel." The chapter begins coverage of Resource Library Contracts by discussing the contracts folder. The chapter explains and illustrates applying style to tables and JSF components with contracts. The chapter also covers writing of contracts for composite components, writing custom themes, using XML to configure contracts, and packaging contracts in JARs under META-INF/contracts.

Chapter 12: Facelets Templating

Mastering JavaServer Faces 2.2 introduced and referenced Facelets in earlier chapters, but this final chapter focuses on Facelets (specifically templating with Facelets). After a brief history of how Facelets supplanted JavaServer Pages as the default View Definition Language for JavaServer Faces, the chapter provides a bullet list of Facelet tags with brief descriptions of each tag in each bullet.

After listing major Facelets tags with brief descriptions, Chapter 12 provides more in-depth discussion and examples of applying Facelets tags such as <ui:param>, <ui:decorate>, <ui:fragment>, <ui:repeat>, <ui:include>, <ui:debug>, and <ui:remove>.

Until reading Mastering JavaServer Faces 2.2, I was not aware of jsfc, but that is covered in the final chapter. The chapter also discusses "Facelets programmatic aspects" such as FaceletFactory, FaceletCache, ResourceHandler, including Facelets programatically, implementing a TagHandler class and implementing Facelets taglib functions.

The section of Chapter 12 titled "Facelets pitfalls" opens with something I've definitely observed: "It is a well-known fact that JSF pitfalls are not easy to understand and fix." This section then focuses on "three common Facelets pitfalls." Chapter 12's Summary is for that chapter only; there is no overall book summary.

Appendix: The JSF Life Cycle

This appendix is barely more than a single page, but has valuable information on the JSF lifecycle depicted in a flow diagram.

General Observations
  • There are numerous code listings in Mastering JavaServer Faces 2.2. These are black text on white background with no line numbers or syntax highlighting. Code is also available online, which is probably preferable because it can be presented in the reader's favorite IDE or text editor with color syntax highlighting and line numbers.
  • Mastering JavaServer Faces 2.2 provides graphics and figures to illustrate points being made. Many of these are in color in the PDF version I reviewed.
  • In multiple cases, the author mentioned a feature that was supposed to be part of JSF 2.x, but that was not working for him at time of writing of the book. I appreciated this being called out as it appears that some of these features may still not be supported in a standard way.
  • The author differentiates between standard JSF features and functionality and features and functionality provided by alternative JSF implementations.
  • NetBeans is referenced a few times in Mastering JavaServer Faces 2.2. In all of these cases, even a person who has not used NetBeans would likely understand the principle being stated.
  • Mastering JavaServer Faces 2.2 is not intended for the developer who is completely new to JavaServer Faces (the author stated this in the Preface: "It is dedicated to JSF developers who have previous experience and want to upgrade their knowledge to the new JSF 2.2."). Rather, this book is focused on providing in-depth details of new features of JSF 2.0 and 2.2 for developers who already have some basic familiarity with JSF. Alternative resources to consider for those entirely new to JSF in preparation for reading Mastering JavaServer Faces 2.2 include the following (some of which I've linked to earlier in this post):
Conclusion

Mastering JavaServer Faces 2.2 provides wide coverage of JavaServer Faces 2.0 and 2.2 additions that have made the framework more powerful and easier to apply. Mastering JavaServer Faces 2.2 assumes that the reader has previous JavaServer Faces experience and does not spend time bringing the reader up to speed on JSF basics before diving into the relatively detailed coverage of features new to JSF with 2.0 and 2.2. The book is best suited for developers who have mostly developed with JSF 1.x and want to start taking advantage of JSF 2 and JSF 2.2 features. This book is not appropriate for someone brand-new to JSF with no previous JSF experience.

Saturday, February 11, 2012

JSF Open Source Throwdown

Optimus Prime's post IceFaces Copies PrimeFaces Line by Line and Brian McKinney's response (New ACE Component Origins) have led to a controversial discussion on the blogosphere regarding legalities and ethics in an open source context. It is interesting to read the perspectives of those associated with PrimeFaces, the perspectives of those associated with ICEfaces, and the community reaction (and here).

Although I tend not to use JavaServer Faces, I have still found the general discussion interesting because the points and counterpoints being made could apply to any open source development projects. Perspectives on what is legal, what is ethical, and what is morale in open source appear to differ greatly among users of these products. Some people think that everything that has been done is legal and ethical. Others believe it is legal but unethical and still others believe there may be copyright infringement even if there are no license issues.

There are numerous good points made in these online discussions that made me think more about the nature of open source. There is no question that there are numerous different perspectives on what's right and wrong in open source, but I'd like to see opinions from well-known open source advocates such as Simon Phipps and Richard Stallman on the matter.

This recent open source controversy is also a reminder of the importance of choosing the appropriate license for one's open source projects. There is always a tenuous balance between wanting to offer a very liberal license to increase adoption and wanting to protect one's work and get appropriate credit/attribution for that work. The Apache Software Foundation license is very friendly to other users, but in this case it seems it may be a little more liberal than the folks at PrimeFaces would have liked.

Saturday, December 13, 2008

Java RIA Momentum

In my previous blog post, I briefly discussed Flex's growing circle of friends that gained a powerful friend with the addition of the Spring Framework and the announcement of the Spring BlazeDS Integration project. To make things even more interesting, this announcement has been made in the same month as the release of JavaFX 1.0 SDK and as the announcement that JBoss will include Google Web Toolkit (GWT) as part of its middleware offerings. Besides the recent announcements of Flex+Spring collaboration, JBoss+GWT collaboration, and the release of JavaFX 1.0 SDK, there is also increased coverage of forthcoming JSF 2.0. All of these announcements are evidence of the battle for Java-based RIA supremacy.

The concept of momentum applies to just about any competitive sporting event one can imagine and often applies to the software development world as well. One interesting point about momentum is that it is difficult to measure quantitatively and is often something we "feel". Another interesting observation related to momentum is that it does not necessarily imply who is winning the overall particular sporting event at this moment, but rather describes who seems to be playing better currently. Even a team or individual losing the match or game might be said to have the momentum if that team or individual is narrowing the difference in score. A team that is widening its lead similarly is often said to have the momentum.

I see similarities in this somewhat nebulous concept of "momentum" in the trends of the software development world as well. Programming languages, approaches and methodologies, and so forth enjoy and lose momentum. For this blog post, I specifically want to focus on the momentum I have observed in the Java-based RIA world. Just as with momentum in sporting events, it is difficult to measure momentum, but it is something that I "feel" based on discussions with other Java developers, on attendance at conferences, and on frequent reading of related blog entries.

From what I have observed in attending conferences such as Colorado Software Summit 2008, in reading blogs, and in talking to fellow self-labeled Java developers is that both Flex and Google Web Toolkit seem to have significant momentum in the Java-based RIA world at this point. JSF seems to have lost significant momentum, though that could change with the 2.0 release. Sun is spending significant resources and energy to try to re-energize momentum for JavaFX that I believe (at least true for me) was damaged by the early announcement at 2007 JavaOne without a 1.0 SDK release until December 2008.

In many ways, the same thing happened to me with JSF; the momentum seemed to be significantly limited due to long delays on the delivering of its promises. I remember hearing about JSF being the next great thing during my development with Struts in early 2001, but it seemed to be many years before it was really ready for prime time. Even now, many are saying that 2.0 (2009) will finally bring JSF to where it needs to be.

When watching sporting events, we can look at the scoreboard to determine who is winning the overall competition (which may not be the team or individual with the current momentum). It is more difficult to see what is winning currently in the Java+RIA arena, but it is interesting to speculate on where current momentum and future potential momentum changes will take the Java-based RIA community in the future. Based on what I "feel" when I talk to others about Java development of RIAs, the current momentum seems to be in Flex's favor (as witnessed by many different events such as the Spring+Flex integration announcement and the defections of many high-profile Swing developers to Adobe) and in GWT's favor (as witnessed by several events including the JBoss+GWT collaboration announcement).

Another category of RIA development that could be argued to be enjoying current momentum is direct Ajax/JavaScript development. Like Flex, this approach is not Java-specific, but is used by Java developers. Current momentum does not guarantee a victory, but it is certainly something every competitor wants. An argument could be made that the current participant that is "winning" is the direct Ajax/JavaScript approach and the real question may be if the growing momentum of Flex, GWT, JavaFX, and other approaches can overtake that lead.

SpringSource and Red Hat/JBoss are major players in the Java-oriented open source community. Their collaborative efforts with Adobe (Flex) and Google (GWT) respectively indicates the momentum enjoyed by Flex and GWT in the Java development world. While using straight Ajax/JavaScript on the front-end with Java on the back-end is also currently popular, Flex and GWT seem to be taking advantage of a common desire among many Java developers to avoid direct contact with JavaScript and DOM browser idiosyncrasies whenever possible.

Finally, all of this is complicated by that fact that many of these approaches can, in fact, be used together. For example, Flex and Ajax/JavaScript can be used together (such as with the Flex-Ajax Bridge). Similarly, there are efforts underway to integrate Flex and JSF such as the JSF Flex Project. Similarly, there are projects surrounding integration of GWT and JSF.

To make matters even more complicated, there are other competitors trying to enter the competition. These include Flash/Flex-like competitors such as Silverlight and Curl. Silverlight, in particular, has many things in its favor, but winning the hearts and minds of Java developers seems like a long-shot. Java developers wishing to developer RIAs might also be interested in the next-generation Java plug-in (the return of the applet) or in one of the numerous Java-based frameworks such as Galileo and Pivot.

In summary and based on my own observations, I'd say that direct Ajax/JavaScript solutions are probably currently winning in terms of number of RIAs being developed with Java on the back-end, but that the momentum is shifting toward Java developers using Flex or GWT. However, the competition is not over yet. The good news is that the RIA options for the Java developer continue to get more diverse and productive.

Thursday, January 10, 2008

Why I Don't Care for JSF

I recall in 2001 as Struts was just starting to take off in popularity that the next big thing was being advertised as JavaServer Faces. I have followed this specification's progress off and on since then, but have been disappointed with JSF implementations each time I have made a real effort to learn to JSF. I have wanted to like it because it is a standard specification and many vendors have been pushing it. Unfortunately, each time I work with JSF, I leave disappointed. It is difficult to summarize all the frustrations and issues, but I think it boils down to truly being far more difficult than it should be. The difficulty of applying JSF is more obvious when it is compared to alternatives such as Flex, OpenLaszlo, Ruby on Rails, WebWork, Tapestry, and even several other Java web frameworks.

It almost seems unfair to compare Flash-based web applications developed with either Flex or OpenLaszlo to JSF. After all, Flex and OpenLaszlo enjoy the ability to compile into applications that run in an environment that supports highly fluid animation and allows developers to code free of concern about browser idiosyncrasies. Flex and OpenLaszlo both allow for developers new to these frameworks to easily begin working with the frameworks and quickly master the basics of each framework. Both OpenLaszlo and Flex provide rich component sets and both are heavily based on standards (XML and ECMAScript).

If an application must be a browser-based application, it is difficult to think of an easier way to accomplish this than by leveraging the abstraction provided by Flash and acquired easily with OpenLaszlo or Flex. While I think Flash-based web applications are easier to build and maintain than DHTML/Ajax-based web applications, the JSF-based applications seem to be the most difficult of all.

I am being relatively kind in my treatment of JSF in this blog entry. Matt Raible, who certainly knows a thing or two about Java-based web development, stated "... JSF sucks. Especially when used with JSP - which is what most folks are doing. JSF continues to be the most over-hyped under-used framework in Javaland." Ouch. Painful but true. Matt also points out something that really irritates me as well regarding JSF; it simply takes too long to be what it wants to be and other frameworks and tools are leaping ahead.

Adam Winer is much nicer about JSF, but acknowledges it is more difficult than it should be in his blog entry Usability Problems in JSF.

In The Real Problem with JSF, Spencer Uresk states that the real problem with JSF is people making misinformed statements about it. While there may be some truth to that, it is my experience that JSF is the most difficult to use of any of the web frameworks that I have tried (and I have tried several). So, while it admittedly may be just me, I personally don't have much use for the seemingly unnecessary complexity of JSF. This is driven home even more whenever I try JSF in the same relative time frame that I work with Flex or OpenLaszlo.

To be fair, some JSF implementations are better than others. However, I grow weary of people arguing about JSF's advantage being its standardization. My experience has been that many JSF implementations have trouble implementing even the core functionality correctly or completely. Some of the commercial (or formerly commercial) JSF frameworks are significantly better, but many of them use proprietary features to be better and that reduces the argument of a standardization advantage for that particular JSF implementation.

Frederic Simon beat me to the punch on comparing JSF to earlier versions of Enterprise JavaBeans. The push from Sun and vendors to use "the standard" despite its many flaws and relative problems compared to other available frameworks feels like EJB 1.x and 2.x being foisted upon us all over again. The Spring Framework and other forces led to making EJB usable and I'd like to think that all these other innovative web frameworks will have the same positive effect on JSF. Unfortunately, many of us have heard the JSF hype repeatedly and been burned repeatedly as we gave it another try. Just as many are reluctant to give up their Spring-based applications to even try the vastly improved EJB 3, it is likely that many of us will be very reluctant to try JSF again if one of these alternative frameworks is satisfying our needs.

In the article Improving JSF by Dumping JSP, Hans Bergsten points our that using JSP as one of JSF's main views is problematic. In that article, he encourages use of other view technologies in conjunction with JSF.

The article Java Opinions: Geary vs Raible on JavaServer Faces provides a nice summary of some of the discussion regarding JavaServer Faces and summarizes my thoughts on it. While it could be argued that it is the implementations that are the problem rather than the specification itself, that doesn't help me feel much better if the implementations are all I have to use. Even if one or two is a decent implementation and the rest are more trouble than they're worth, it reduces the value of a "standard" because I cannot easily switch between them or rely on the same behavior across them.

Matt Long writes of his frustration with JSF in Nobody Users JavaServer Faces and he compares it to ASP .NET (which I have not used). He says, "As much as I despise ASP .NET, it is a dream compared to JSF." He adds, "And that brings me to the point. JSF is a technology that looks good on paper, but when it comes to actually using it, it stinks." This is echoed by others critical of JSF (including me) who like many things about it conceptually, but find it much dissatisfying in practice. Matt also mentions another telling characteristic of JSF -- even the "introductory tutorials" must use long code samples and explanations even for the most basic of applications. I liked a quote from a person providing feedback to this article (and defending JSF): "That said, in it's current offering it's much more a bare fundamental technology on which interesting things can be built, than a ready to use high-level framework." Since 2001, JSF has consistently seemed to be "almost there."

I think most people who have used JSF directly would have a hard time arguing that JSF simplifies web development. However, one of the big arguments for JSF has been that tools would make it easier to use and this is where vendors seemed to really be interested from the beginning. After all, any chance to sell a tool to make a complicated framework or language easier to use is better for a vendor's business than a framework that does not need a tool. One of the facets of the Agile Manifesto is "Individuals and Interactions over processes and tools." If I have my choice, I'd rather have something simple to write manually (and still use tools if I choose to) rather than something that is so complicated or tedious (EJB 1.x, EJB 2.x, XML Schema, etc.) that they almost necessarily require use of tools.

I have heard proponents of JSF argue that simply reading a good book on JSF will overcome the many complaints with JSF. The problem with this argument, in my opinion, is that one probably doesn't need to read a good book to get well under way with OpenLaszlo or Flex. Admittedly, a good book comes in handy as one progresses with either of these frameworks, but I did not find myself relying nearly as much on these books as I needed to rely on my JSF book for even simple things (or things that should be simple).

From its beginning, one of the mantras of JSF has been its desire to allow for a flexible architecture in which view technologies could be easily swapped. For those who truly need this, the complexity of JSF may be justified if the ease of swapping view technologies becomes reality. Generally speaking, with great flexibility comes great complexity. Why endure the complexity if you don't really need the flexibility?

I am curious to see if JSF is able to survive and eventually thrive. To do so, it may have to go through a evolution or even revolution like EJB did. It seems like the best bet for a successful and less painful JSF experience is to use a framework like JBoss Seam, Oracle's Application Development Framework (ADF), or Apache Beehive (former BEA product). Note, however, that Seam and ADF offer much more than simply JSF implementations.

There is already tough competition for JSF in the web development community and the rise of Silverlight and JavaFX to emulate Flash will likely make the competition for web developers' hearts and minds even more fierce. There is much I like about Java (both SE and EE), but I have serious doubts about the viability of JSF in the near-term future without significant changes. JSF has certainly come a long way, but I question whether it has come along far enough fast enough to remain a viable option compared to the many other choices out there. Just as "being the standard" was not enough for earlier versions of EJB, this cannot continue to be the main advantage of JSF if it is to be successful.

We all know that the major players in web (Google, Amazon, etc.) using Ajax technologies and Flex. Do they use JSF as well? I don't know and it certainly doesn't seem to be advertised as well if they do.

This blog entry is not meant to belittle anyone who has had success with JSF. After all, we each should select technologies that work best for us, for our clients, and for the problem at hand. For example, those who need their application rendered on many different platforms/devices and have access to or willingness to write the appropriate render kits, JSF may be the best alternative.

UPDATE (28 January 2008): Ed Burns, co-lead of the JavaServer Faces specification, left a feedback message below with this reference to a JSF 2.0 requirements scratch pad. It is reassuring to see active work to improve JSF. It will be interesting to see if JSF can compete with the increasingly popular Flex+Java combination as well as with JavaFX if that starts getting heavy adoption.

This blog entry is meant to be a simple summary of things I have experienced with JSF, especially when compared to Flex. While my experience leads me to strongly prefer Flex or OpenLaszlo over JSF for web-based applications, I believe just as strongly in the principle of "To each his or her own!" In addition, I'd like to see JSF succeed because, when all else is equal (or even very close to being equal), I do prefer to develop to the standards-based product.

Here are some other interesting opinions on JSF. I have mixed some positive reviews of JSF with the negative ones.

Ed Burns Blog ADDED 28 January 2008

JSF for Nonbelievers: Clearing the FUD about JSF

What to do about Java and JSF?

JSF: The Ultimate in Flexibility? Or Complexity?

Developing Web Applications with JavaServer Faces

JavaServer Faces: Web Applications Made Easier

JavaServer Faces Versus Tapestry

GAME OVER - Java Sever Faces (Added 3 May 2008)

Is JSF Fixable? (see feedback as well for interesting counterarguments) [Added 5 November 2008]

JSF Anti-Patterns and Pitfalls (see feedback as well) [Added 20 December 2008]