views:

26

answers:

0

Hi all,

i would like to use Spring Web Flow and JSF 2, but it doesn't work. If I use a h:commandButton the transition is not executed and the page is only refreshed.

My configuration is:

web.xml:

  <!-- Initializing JavaServer Faces, *NOT* used at runtime due to Spring Web Flow -->
  <!-- FacesServlet -->
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <!-- The servlet is loaded on startup to be reachable for requests. -->
    <load-on-startup>1</load-on-startup>
  </servlet>

  <!-- Mapping for FacesServlet -->
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
  </servlet-mapping>


  <!-- Initializing JBoss RichFaces -->
  <!-- Plugging the "Blue Sky" skin into the project -->
  <context-param>
    <param-name>org.richfaces.SKIN</param-name>
    <param-value>blueSky</param-value>
  </context-param>

  <!-- Making the RichFaces skin spread to standard HTML controls -->
  <context-param>
    <param-name>org.richfaces.CONTROL_SKINNING</param-name>
    <param-value>enable</param-value>
  </context-param>

  <!-- Defining and mapping the RichFaces filter -->
  <filter>
    <filter-name>RichFaces Filter</filter-name>
    <filter-class>org.ajax4jsf.Filter</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>RichFaces Filter</filter-name>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <!-- <dispatcher>ERROR</dispatcher> -->
  </filter-mapping>

  <!-- Turn off the VDL viewhandler because of the limited JSF 2.0 support of RichFaces -->
  <context-param>
    <param-name>javax.faces.DISABLE_FACELET_JSF_VIEWHANDLER</param-name>
    <param-value>true</param-value>
  </context-param>


  <!-- Initializing Spring Web Flow -->
  <!-- The front controller of this Spring Web application, responsible for handling all application requests -->
  <servlet>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/config/web-application-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <!-- Map all /spring requests to the Dispatcher Servlet for handling -->
  <servlet-mapping>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <url-pattern>/swf/*</url-pattern>
  </servlet-mapping>

web-application-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                           http://www.springframework.org/schema/context
                           http://www.springframework.org/schema/context/spring-context-2.5.xsd"&gt;

  <context:annotation-config />

  <!-- Imports the configurations of the different infrastructure systems of the application -->
  <import resource="webmvc-config.xml" />
  <import resource="webflow-config.xml" />

</beans>

webflow-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:webflow="http://www.springframework.org/schema/webflow-config"
       xmlns:faces="http://www.springframework.org/schema/faces"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                           http://www.springframework.org/schema/webflow-config
                           http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd
                           http://www.springframework.org/schema/faces
                           http://www.springframework.org/schema/faces/spring-faces-2.0.xsd"&gt;

  <!-- Executes flows: the central entry point into the Spring Web Flow system -->
  <webflow:flow-executor id="flowExecutor" />

  <!-- The registry of executable flow definitions -->
  <webflow:flow-registry id="flowRegistry" flow-builder-services="facesFlowBuilderServices" base-path="/WEB-INF/flows">
    <webflow:flow-location-pattern value="*-flow.xml" />
  </webflow:flow-registry>

  <!-- Handles requests mapped to the Spring Web Flow system -->
  <bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">
    <property name="flowExecutor" ref="flowExecutor"/>
    <!-- Integrates the ability to use RichFaces Ajax components -->
    <property name="ajaxHandler">
      <bean class="org.springframework.faces.richfaces.RichFacesAjaxHandler"/>
    </property>
  </bean>

  <!-- Configures the Spring Web Flow JSF integration -->
  <webflow:flow-builder-services id="facesFlowBuilderServices" view-factory-creator="viewFactoryCreator"/>

  <!-- Maps selected view identifiers to JSF-files specified by the defined jsfViewResolver -->
  <bean id="viewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
    <property name="viewResolvers">
      <list>
        <ref bean="jsfViewResolver"/>
      </list>
    </property>
  </bean>

</beans>

webmvc-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"&gt;

  <!-- Maps logical view names to JSF-Files (e.g. 'search' to '/search.jsp' -->
  <bean id="jsfViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.faces.mvc.JsfView"/>
    <property name="prefix" value="/" />
    <property name="suffix" value=".jsp" />
  </bean>

  <!-- Maps request URIs to controllers -->
  <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
      <value>
        /*-flow=flowController
      </value>
    </property>
    <property name="defaultHandler">
      <!-- Selects view names to render based on the request URI: e.g. /main selects "main" -->
      <bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
    </property>
  </bean>

</beans>

faces-config.xml:

<?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>
  </application>
</faces-config>

test-flow.xml:

<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/webflow
        http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"&gt;

 <view-state id="Testpage">
    <transition on="test" to="Nextpage" />
 </view-state>

 <view-state id="Nextpage" />

</flow>

Testpage.jsp:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//DE">
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<!-- RichFaces tag library declaration -->
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>


<HTML>
<HEAD>
<TITLE>Testpage</TITLE>
</HEAD>
<BODY>
<f:view>
<h:form>

  <a href="${flowExecutionUrl}&_eventId=test">Submit</a>

  <input type="submit" name="_eventId" value="test" />

  <h:commandButton id="test" action="test" value="test"/>

</h:form>
</f:view>
</BODY>
</HTML>

The link and the first button works, but the JSF-Button only refresh's the page!

PLEASE HELP ME!!!