JSF 2.x + Spring 3.2 Integration?

被刻印的时光 ゝ 提交于 2019-12-21 02:56:08

问题


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 enough knowledge in spring 3.2 and completed one small project in spring.

Now I am new to JSF and I some created basic JSF example .I would like to use the JSF features and its components for my new Spring + JSF project.

The links that I came out for JSF + Spring Integration are given below ,

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

The resources I found , does not helped me and that was very old post.

Can any one provide me a sample Integration for JSF 2.X + Spring 3.x MVC with controller and view resolver and this would help a lot of users who really seeking for a working one..

Hope our stack users will help me.


回答1:


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




回答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:

  • Primefaces
  • RichFaces
  • IceFaces

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.



来源:https://stackoverflow.com/questions/18527409/jsf-2-x-spring-3-2-integration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!