Two J2EE technologies are becoming dominant in the Java environment: Spring and Java ServerFaces.

Spring beans could be easily integrated in a JSF project. Spring Beans can coexists with JSF managed beans or interact directly with the view.

The steps necessary to use Spring in a JSF projects are the following:


Spring libraries must be accessible 🙂


In web.xml you have to declare your spring listener:


To use the request values between the view (jsp/jsf) ad the bean you have to add a second listener:



In faces-config.xml usually you define the managed beans. To use spring beans you have to add the following lines:



In the applicationContext.xml you have to declare your beans like a standard Spring application, the only difference is the property scope:

<bean name ="personMB" class="ch.genidea.ofac.web.jsf.Person" <strong>scope="request"</strong>>
<property name= ... />

Usually the scope property is set as singleton (default). For the web application you have 3 possibilities:


In your page you can call the bean directly :

<h:outputText value="First name"/> <h:inputText value="#{personMB.firstName}" id="personName"/>
<h:outputText value="Family name"/> <h:inputText value="#{personMB.lastName}" id="personFamilyName"/>