Scaffolding JSF/Primefaces and Spring
This tutorial walks you through the generation of software components for JavaServer Faces (JSF). Spring scaffolding with JSF requires a MyEclipse Spring or Bling subscription. 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
Duration Time: 20 Minutes
Don't have MyEclipse? Download Now
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.
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.
Select a JavaServer Faces version in the project configuration.
Accept default JSF capabilities.
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.
- Download both EL libraries: EL API and EL implementation.
- In the Servers view, double-click MyEclipse Tomact.
- Click the Open launch configuration link.
- 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.
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 18.104.22.168 or later installed.
- Right-click CustomersJsfApp, and select Run As>MyEclipse Server Application. Select the MyEclipse Tomcat server.
MyEclipse 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.
- 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.
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.