Skip to Main Content
Spring: A Developer's Notebook
book

Spring: A Developer's Notebook

by Bruce Tate, Justin Gehtland
April 2005
Intermediate to advanced content levelIntermediate to advanced
216 pages
4h 44m
English
O'Reilly Media, Inc.
Content preview from Spring: A Developer's Notebook

Integrating JSF with Spring

Spring comes with a JSF variable resolver that lets you use JSF and Spring together. You can access Spring beans using JSF and vice versa. Integrating JSF and Spring lets you tap into the capabilities of two of the most powerful server-side Java frameworks.

How do I do that?

You already did! In the previous example you used value bindings to bind JSF components to model objects. For example, in /bike.jsp, you did this:

         ...
         <h:form>
            <h:dataTable value="#{rentABike.bikes}" var="bike">
               <h:column>
                  ...
               </h:column>
            </h:dataTable>
            ...
         </h:form>
         ...

The #{rentABike.bikes} value binding references the bikes property of the bean named rentABike. Recall that previously, the rentABike bean was defined in a Spring configuration file, like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dt\
d/spring-beans.dtd">

<beans>
    <bean name="rentABike" class="com.springbook.ArrayListRentABike">
        <property name="storeName"><value>Bruce's Bikes</value></property>
    </bean>

    ...
</beans>

Things are no different in the JSF version of Bruce's Bike Shop, which means that the JSF expression #{rentABike.bikes} accesses a Spring bean. That's made possible by the DelegatingVariableResolver from the org.springframework.web.jsf package. You declare that variable resolver, which extends the JSF expression language to include references to Spring beans, in the faces configuration file:

<faces-config> <application> <variable-resolver> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

JavaBeans Unleashed

JavaBeans Unleashed

Dr. Donald Doherty, Rick Leinecker
Beginning Spring

Beginning Spring

Mert Caliskan, Kenan Sevindik, Rod Johnson, Jürgen Höller
Hibernate Search in Action

Hibernate Search in Action

Emmanuel Bernard, John Griffin

Publisher Resources

ISBN: 0596009100Supplemental ContentErrata Page