Sorry to ask this question and it may be a duplicate of other similar threads in Stack overflow.Those similar thready does not work in my situation.
I am having a quite
First of all: you shouldn't use JSF and Spring MVC together since they compete against each other! (That's my opinion!)
Take a look at these links:
JSF 2.0 + Spring integration example
Integrating Spring Web Flow with JSF
Configuring Spring MVC for use with JSF 2
In my opinion, Spring
and JSF
- both could be used just fine. It, of course, mostly depends on your requirements and preferences of using those frameworks.
Spring - it has very nice ways of transactions management, dependency injection, security and many other features, however - plain JSF
does not provide this kind of features out of the box, but JSF has very nice way of rendering views. So these features from both frameworks mixed up together could result in simplicity. JSF has a variety of it's frameworks which are built on it, like:
In my opinion, you could simplify your views development, if you had been using JSF
. JSF has ManagedBean(s), which depending on your configuration serves your requests, like
Spring controllers does.
Actual configuration is pretty straight forward. You need to have:
faces-config.xml
file which contains SpringBeanFacesELResolver:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
<navigation-rule>
<!-- your rules here -->
</navigation-rule>
</faces-config>
Spring applicationCotext.xml
file. Usual spring config, nothing JSF
specific.
Your web.xml
which should look something like this:
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<!-- other config -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/applicationContext.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<!-- other of config -->
</web-app>
The most pretty cool thing in JSF
is View Scope, which would be lost by default, if you had been using JSF
with Spring
, but definitely you don't want to lose it. This explains how to make View Scope work in JSF
and Spring
integration.
If I would be building some application from scratch, I would choose these two frameworks and integrate them together, but this is just my opinion. Hope this clears some things for you.