Scaffolding JSF/Primefaces and Spring

This tutorial walks you through the generation of software components for JavaServer Faces (JSF).  In this tutorial, you will learn how to:

  • Scaffold from a database table into an existing project
  • Configure servers for JSF 2.0 support
  • Deploy a scaffolded application
Customizing Spring code generation requires a MyEclipse Spring or Bling subscription.

1. Create a Web Project

Create a MyEclipse Web project called CustomersJsfApp.

Note: If you get a popup regarding the project compiler compliance level not matching the workspace default, specify that you want to use a custom setting for the project by clicking Yes.

New web project

2. Scaffold from Database Tables

Scaffolding with JSF requires the same steps as scaffolding with Spring MVC. Follow the steps in Scaffolding a Spring MVC Application with the following exceptions:

Select the Generate checkbox for JSF on the Select Web Client Type wizard page.

Selecting the JSF web client

Select a JavaServer Faces version in the project configuration.

Configuration options

Accept default JSF capabilities.

Adding JSF capabilities

3. Configuring Servers for JSF 2.0 Support

Extra server configuration is required when targeting a Java EE 5 compatible server such as Tomcat or WebSphere 7, or Tomcat 7. This section provides information on the configurations required in each case.

Updating Expression Language (EL) for Tomcat Servers

To run JSF 2.0 applications on Tomcat 6 or 7, you need to  update the expression language (EL) libraries in Tomcat. For this tutorial,  you deploy to MyEclipse Tomcat, and the easiest way to update  the EL libs is to prepend the new libraries in the classpath.

  1. Download both EL libraries: EL API and EL implementation.
  2. In the Servers view, double-click MyEclipse Tomact.

    Configuring the server connector
  3. Click the Open launch configuration link.

    Opening launch configuration
  4. Select the Classpath tab, select User Entries, and click Add External JARs to add the two downloaded EL libraries to the classpath. Click Up to move the JARs to the top of the list.

    Prepending libraries

Note: If you are deploying to Tomcat 6 or 7 (instead of MyEclipse Tomcat), you need to update the EL libraries in Tomcat.

Configuring WebSphere 7 for JSF 2.0 Support

To configure WebSphere 7 for JSF 2.0 support, you must create a WebSphere shared library that has the isolated classloader option enabled. Modules using JSF 2.0 are then associated with the library, which starts JSF 2 instead of JSF 1.2. The configuration steps must all be done outside of MyEclipse. Please follow the IBM WebSphere instructions to configure your WAS 7 server. (Another reference for these steps can be found at http://wasbehindtheglass.blogspot.co.uk/2011/11/myfaces-20-and-websphere-application.html.)

Note: The WebSphere Applicaton Server must have fix pack or later installed.

4. Deploy the App

  1. Right-click CustomersJsfApp, and select Run As>MyEclipse Server Application. Select the MyEclipse Tomcat server.

    Deploying the applicationMyEclipse Tomcat starts. The first page is a dashboard for accessing all scaffolded web clients. Because this tutorial only scaffolded a single database table for JSF 2.0, the only option under JavaServer Faces is View Customers.
  2. Click View Customers to see generated JSF 2.0 application in operation. If you want to run the JSF application in a separate browser, use the following URL: http://localhost/CustomersJsfApp/.


The JSF 2.0 application can be used to list all customers, view customer details, edit customer details, delete customers and add new customers.

Customer app list
Customer app edit details

5. What’s Generated?

To ease your way into code generation with ME4S, this tutorial involved scaffolding from only a single database table. Therefore, only the software components for managing a single entity were generated, and there were no entity relationships. When you start generating for multiple entities, potentially with entity relationships, there are many more software components generated than were generated with this tutorial. Even though there’s a lot more code, it is grouped and organized as shown in the following  images.

Generated scaffolding