繁体   English   中英

JSF 2.x + Spring 3.2集成?

[英]JSF 2.x + Spring 3.2 Integration?

很抱歉提出这个问题,它可能与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的示例集成, 带有控制器和视图解析器 ,这将有助于许多真正寻求工作的用户。

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

在我看来, 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>

Spring applicationCotext.xml文件。 通常的spring配置,没有特定的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>

JSF最酷的东西是View Scope ,默认情况下会丢失,如果你一直在使用JSFSpring ,但绝对不想丢失它。 解释了如何使View Scope在JSFSpring集成中工作。

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

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

看看这些链接:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM