JSF 2.x + Spring 3.2集成?

Hum*_*ing 2 java spring richfaces spring-mvc jsf-2

很抱歉提出这个问题,它可能与Stack溢出中的其他类似线程重复.这种情况在我的情况下不起作用.

我有一个相当足够的知识,在春季3.2并完成了一个小项目的弹簧.

现在我是JSF的新手,我创建了一些基本的JSF示例.我想将这些JSF功能及其components用于我的新Spring + JSF项目.

我为JSF + Spring Integration出来的链接如下,

http://papweb.wordpress.com/2011/07/29/spring-mvc-3-jsf-2-with-maven-2-and-tomcat/

http://blog.terrencemiao.com/archives/spring-3-shacks-up-jsf-2-the-maverick-way

我发现的资源并没有帮助我,那是非常古老的帖子.

任何人都可以为我提供JSF 2.X + Spring 3.x MVC的示例集成,带有控制器和视图解析器,这将有助于许多真正寻求工作的用户.

希望我们的堆栈用户能帮助我.

Pau*_*nis 6

在我看来,SpringJSF-都可以使用就好了.当然,它主要取决于您使用这些框架的要求和偏好.

Spring - 它有非常好的事务管理方式,依赖注入,安全性和许多其他功能,但是 - 普通的JSF不提供开箱即用的这种功能,但JSF有非常好的渲染视图的方式.因此,两个框架中的这些功能混合在一起可以简化.JSF有很多基于它构建的框架,例如:

在我看来,如果你一直在使用,你可以简化你的视图开发JSF.JSF有ManagedBean,它取决于你的配置服务于你的请求,就像Spring控制器那样.

实际配置非常简单.你需要:

faces-config.xml包含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>
Run Code Online (Sandbox Code Playgroud)

弹簧applicationCotext.xml文件.通常的春季配置,没什么JSF特别的.

web.xml应该看起来像这样:

<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>
Run Code Online (Sandbox Code Playgroud)

在最很酷的事情JSF查看范围,这将在默认情况下会丢失,如果你一直在使用JSFSpring,但绝对不想失去它.解释了如何使View Scope工作JSFSpring集成.

如果我将从头开始构建一些应用程序,我会选择这两个框架并将它们集成在一起,但这只是我的观点.希望这能为你解决一些问题.


Phi*_*der 5

首先:你不应该一起使用JSF和Spring MVC,因为它们相互竞争!(这是我的意见!)

看看这些链接: