Using JSF with Spring

In this section you'll see how to use JavaServer Faces and Spring together. Then we'll see how you can use the JSF expression language to access Spring beans.

JSF, like Spring MVC and Tapestry, is a second-generation web application framework. The first generation, represented by frameworks such as Struts, have taught us a lot over the past three or four years, and better frameworks have evolved as a result. For example, both JSF and Tapestry have component models, which makes it easier to extend those frameworks and share that work with others.

JSF, Tapestry, and Spring MVC also support value bindings—wiring HTML elements (in the case of Spring MVC) or components (JSF and Tapestry) to JavaBean properties. In that simple mechanism lies a lot of power. More about that later...

In the first example, you'll implement Bruce's Bike Shop using JSF and Spring.

How do I do that?

The JSF version of Bruce's Bike Store looks nearly identical to the Struts and Spring MVC versions, as you can see from Figure 3-3.

JSF version of the main page

Figure 3-2. JSF version of the main page

You can dive right into the JSF version of bikes.jsp:

<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>

<html>
   <f:view>
      <head>
         <title>
            <h:outputText value="#{rentABike.storeName}"/>

Note

These tags are from the JSF tag libraries.

 </title> </head> <body> <h1><h:outputText ...

Get Spring: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.