“Pro JSF and HTML5” Book Review by Werner Punz

Attached below the review of Werner Punz (Senior software developer for Irian GmbH, Apache MyFaces Committer, and a member of the JSF Expert Group) about the “Pro JSF and HTML5” book:

Pro JSF and HTML5 Book

Pro JSF and HTML5 Book

Good but not perfect
“The book itself is a crash course in JSF with extensive JSF 2.2 coverage and component coverage.

The first part of the book is an introduction into JSF and JSF 2.2, the second part walks you through component creation the third part covers two of the most widely used component libs and the fourth part walks you through an entire JSF application utilizing Java EE 7.

Well what should I say, while I wished some parts were covered more deeply, like the already extensive component creation part or the Java EE application walk-through which should have gotten more explanatory coverage in the Java EE area, I personally guess that the book as JSF 2.2 reference and as a tutorial book for JSF fulfills its purpose very well.

The problem I see simply is if you want to cover component creation for JSF on its own with all the special cases for different component types, you probably need a book on its own, the same goes for a full blown Java EE application with all its little details on which pattern to apply where and why, this would be also another book which then should omit the JSF tutorial part.

I will give the book 4 stars as very good JSF 2.2 and component creation reference and good JSF tutorial, but one star less due to the lack of depth especially in the application walk-through which should have gotten a bit more explanation on the Java EE side of things.”

Reference:

http://www.amazon.com/review/R1RQKD0WJN7QDB

The book in Amazon:

http://www.amazon.com/Pro-JSF-HTML5-Building-Components/dp/1430250100

JSF 2.3 Part2, Using @inject for FacesContext

One of the wonderful features of the upcoming JSF 2.3 is the ability to inject many JSF objects such as UIViewRoot, ViewMap, ApplicationMap, ExternalContext and FacesContext. In this post, I will show you how to simply inject FacesContext without having to use the old way FacesContext.getCurrentInstance().

Continuing working on the sample that was introduced in the previous post, let’s modify User managed bean to get FacesContext in order to display an information message to the user once the operation is done. The following code snippet shows the modified User managed bean.

package beans;

import java.io.Serializable;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

@Named
@RequestScoped
public class User implements Serializable {
    private static final long serialVersionUID = 4629817047379532658L;
    private static final String INFO_MESSAGE = "Operation is done ...";
        
    private String name;
    
    @Inject
    FacesContext facesContext;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String greet() {
        facesContext.addMessage("form1", new FacesMessage(FacesMessage.SEVERITY_INFO, INFO_MESSAGE, INFO_MESSAGE));
        
        return null;
    }
}

As shown, all what you need to inject FacesContext in your managed bean is to annotate its declared instance with @inject annotation.

Running Application on GlassFish 4.1

In order to run our JSF application this time on GlassFish, we need to build Mojarra jars for GlassFish and then configure them on the server as follows:

  1. First of all, you need to make sure that you have both SVN and Apache Ant installed and configured in your operating system.
  2. Check out Mojarra 2.3 source code using the following SVN command:
    svn checkout https://svn.java.net/svn/mojarra~svn/trunk

    In order to build the JSF Mojarra jars for GlassFish then create a new file called build.properties under trunk. Then copy build.properties.glassfish file (which is located directly under trunk) content into it. Do not forget to set jsf.build.home property to the directory in which the sources were checked out into as follows for example.

    # --------------------------------------------------
    # Set this to the directory in which the sources
    # were checked out into
    # --------------------------------------------------
    jsf.build.home=/Users/hazems/projects/mojarra23/trunk
  3. CD to the jsf.build.home path, and then execute the following ant command:
    ant clean main
  4. After the successful execution of the previous command, you can get Mojarra jars from:
    1. jsf-api-intermediate.jar from trunk/jsf-api/build/lib directory.
    2. javax.faces.jar from trunk/jsf-ri/build/lib directory.
  5. Finally, overwrite the default javax.faces.jar file under glassfish-4.1/glassfish/modules with the new built javax.faces.jar file, and deploy our JSF application to GlassFish. After running our JSF application, you can see the information message after clicking "Greet" button as shown below.
    Screen Shot 2014-12-21 at 4.03.07 AM

Getting the JSF sample source code:

The sample source code is available in GitHub:
https://github.com/hazems/jsf2.3-work/tree/master/sampleJSF2

JSF 2.3 Part1, Getting Started

It is really not so early to start working with the upcoming JSF 2.3 and testing it. In this post, I will show you how to get started in JSF 2.3 by building JSF (Mojarra) jars from its source then use them for your JSF 2.3 application which will run in Tomcat 7.

Building JSF Jars from SVN:

  1. First of all, you need to make sure that you have both SVN and Apache Ant installed and configured in your operating system.
  2. Check out the source code using the following SVN command:
    svn checkout https://svn.java.net/svn/mojarra~svn/trunk
    
  3. In order to build the JSF Mojarra jars for Apache Tomcat then create a new file called build.properties under trunk. Then copy build.properties.tomcat file (which is located directly under trunk) content into it. Do not forget to set jsf.build.home property to the directory in which the sources were checked out into as follows for example.
    # --------------------------------------------------
    # Set this to the directory in which the sources
    # were checked out into
    # --------------------------------------------------
    jsf.build.home=/Users/hazems/projects/mojarra23/trunk
    
  4. CD to the jsf.build.home path, and then execute the following ant command:
    ant clean main
    
  5. After the successful execution of the previous command, you can get Mojarra jars from:
    1. jsf-api-intermediate.jar from trunk/jsf-api/build/lib directory.
    2. javax.faces.jar from trunk/jsf-ri/build/lib directory.

Configuring your first JSF 2.3 application:

Simply all what you need to work with JSF 2.3 in Tomcat 7 is to do the following:

  • Place the two Mojarra jars in step 4 in your web application WEB-INF/lib folder.
  • Set the JSF version in the faces-config.xml to 2.3 as follows.
    <?xml version='1.0' encoding='UTF-8'?>
    <faces-config version="2.3"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_3.xsd"> 
    </faces-config>
    
  • Then now, you can write your JSF application and it will be powered by the upcoming JSF 2.3. I made a very basic JSF 2.3 sample which you can reach its code in the following GitHub URL:
    https://github.com/hazems/jsf2.3-work/tree/master/sampleJSF1
  • Screen Shot 2014-12-20 at 1.07.36 AM

    In my next JSF 2.3 posts, I will show you some of the JSF 2.3 implemented features “so far” in order to allow you to start working with them so stay tuned.

    Creating JSF RESTful pages

    In a web browser, a bookmark allows users to get back to a given web page at any time. Users can share bookmarkable pages with other users by just sharing a page URL (with its required parameters). Bookmarkable pages are also friends to search engines because they can be indexed by search crawlers. Sometimes you might want to create a bookmarkable page programmatically, with Java for instance. Here’s how to create bookmarkable pages in Java EE applications using the JavaServer Faces (JSF) framework.

    Read the full article in Wazi

    Back from JavaOne Russia 2013

    I just get back from JavaOne Russia that was held in Moscow 23-24 April 2013. JavaOne Russia is the biggest Java Conferences in Eastern Europe. The conference organization was great and there were a lot of attendees in the conference sessions.
    I had the chance to present “JSF Mashups in Action” in 24 April:

    "JSF Mashups in Action" session

    “JSF Mashups in Action” session

    I would really like to thanks all the attendees of my session, they really made the session very interactive. I also appreciate the nice feedback that I got either verbally or from the tweets about the session:
    Tweets

    I uploaded my JavaOne Russia 2013 session in speakerdeck.com, It is attached below:

    Have a nice time

    Speaking in JavaOne Russia 2013

    JavaOne Russia

    JavaOne Russia

    The next Wednesday, Apr 24, 16:45 – 17:45, I will be speaking in JavaOne Russia about [CON1112] JSF Mashups in Action. The session will be practical, I will talk about Mashup development, common Mashup scenarios, and the current challenges of developing Mashups. I will explain how to utilize the JSF powerful component-oriented architecture and its 2.x Ajax capabilities in order to overcome most of these challenges for creating rich Mashups. In the session, I will build many interactive Web 2.0 Mashups to show how it is possible to create rich Mashups in the JavaServer Faces world with the least required Java and JavaScript code. I wish that all of you will enjoy the session. My session will be held in San Francisco Hall, Crocus Expo International Exhibition Center, Moscow:
    http://eng.crocus-expo.ru/exhibitioncenter/aboutcenter.php.

    Personally, it is my first time to visit Moscow, beside enjoying technical stuff, I would like to visit some tourist places in Moscow such as kremlin and Moscow Red square and may be other interesting places, any suggestions 🙂 ?

    I really wish to see all of you there in JavaOne Russia!