Coming Up for Air

Bootstrapping a JSF 2 project

I needed a break this afternoon, so I thought I’d see how easy it is to bootstrap a JSF 2 project. One of the biggest complaints about JSF 1.x is all that XML, so JSF 2 is aiming to fix that. How have we done so far? Based on this quick look (which is my first from-scratch JSF 2 app), really, really well.

Here are the steps I took:

  • Create a web app project using the Maven archetype (because I’m lazy that way : ) :

mvn archetype:create -DartifactId=my-webapp \
  • Add FacesServlet to web.xml:

    <servlet-name>Faces Servlet</servlet-name>
    <servlet-name>Faces Servlet</servlet-name>
  • Add the JSF 2 jars (and their repo) to pom.xml:

        <name> Repository for Maven</name>
  • Create a managed bean:

@ManagedBean(name="main", eager=true)
public class MainBean {
    public MainBean() {
        System.err.println ("MainBean starting up!");
    public String getText() {
        return "Here is some text!";
  • Create the view:

<!DOCTYPE html
      PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns=""
        <title>Should Not Be Displayed</title>
        <ui:define name="content">
  • Build, deploy, browse

Your web browser should now say "Here is some text!"

Did you notice that all but two of those steps are things you would do for any Java web app? As soon as someone creates a JSF 2 Maven archetype, even that can be simplified. Also notice that there was no mention of faces-config.xml. The application doesn’t have one. Granted, this is an insanely simple application, so the need for faces-config.xml may still arise (navigation comes to mind, but I think we’re working on a simplification for that too).

The rule of thumb seems to be that JSF is not well-suited for smaller, simpler apps where things like Grails, RoR, etc. are a better choice. I think we’ll see that JSF 2 changes that.


Sample quote

Quote source