Announcement Announcement Module
Collapse
No announcement yet.
Problem with JSF and Spring WebFlow Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with JSF and Spring WebFlow

    Hello,

    I want to use Java Server Faces with Spring Webflow (2.0.6) but it does not work correctly ...

    The webpage itself looks very nice but the problem is that the action event (of my commandButton) is not recognized by the flow. So the state does not change to the next view-state "step2".

    Does anybody know what's going wrong?

    I'am really new at spring and webapplications. So it would be nice if you could give me some more detaild information.

    Thank you very much!

    best regards

    web.xml:
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    	version="2.4">
    
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>
    			/WEB-INF/services-config.xml
    		</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>phonebook</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<init-param>
    			<param-name>contextConfigLocation</param-name>
    			<param-value>
    				/WEB-INF/phonebook-webflow-config.xml
    				/WEB-INF/phonebook-servlet-config.xml
    			</param-value>
    		</init-param>
    		<load-on-startup>0</load-on-startup>
    	</servlet>
    
    	<servlet-mapping>
    		<servlet-name>phonebook</servlet-name>
    		<url-pattern>*.htm</url-pattern>
    	</servlet-mapping>
    
    	<welcome-file-list>
    		<welcome-file>index.jsp</welcome-file>
    	</welcome-file-list>
    
    	<servlet>
    		<servlet-name>faces Servlet</servlet-name>
    		<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    
    	<!-- Use JSF view templates saved as *.xhtml, for use with Facelets -->
    	<context-param>
    		<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    		<param-value>.xhtml</param-value>
    	</context-param>
    
    	<servlet-mapping>
    		<servlet-name>faces Servlet</servlet-name>
    		<url-pattern>*.xhtml</url-pattern>
    	</servlet-mapping>
    
    	<listener>
    		<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
    	</listener>
    
    </web-app>
    faces-config.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN" "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
    
    <faces-config>
    	<application>
    		<variable-resolver>
    			org.springframework.web.jsf.DelegatingVariableResolver
    		</variable-resolver>
    
    		<!-- Enables Facelets -->
    		<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
    
    	</application>
    </faces-config>
    phonebook-flow.xml:
    Code:
    <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"
    	start-state="step1">
    
    	<on-start>
    		<set name="flowScope.person" value="personFactory.getNewPerson()"></set>
    	</on-start>
    
    	<view-state id="step1" view="step1">
    		<transition on="next" to="step2" />
    	</view-state>
    
    	<view-state id="step2" view="step2">
    		<transition on="previous" to="step1" />
    	</view-state>
    
    </flow>
    step1.xhtml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml"
    	xmlns:ui="http://java.sun.com/jsf/facelets"
    	xmlns:h="http://java.sun.com/jsf/html"
    	xmlns:f="http://java.sun.com/jsf/core"
    	xmlns:c="http://java.sun.com/jstl/core">
    <body>
    <h1>Testfrom (Schritt 1)</h1>
    <h:form>
    	<p>Vorname: <h:inputText id="firstname"
    		value="#{flowScope.person.firstname}" /></p>
    	<p>Nachname: <h:inputText id="surname"
    		value="#{flowScope.person.surname}" /></p>
    	<p>Telefon: <h:inputText id="phonenumber"
    		value="#{flowScope.person.phonenumber}" /></p>
    
    	<h:commandButton value="next" action="next" />
    </h:form>
    </body>
    </html>
    step2.xhtml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml"
    	xmlns:ui="http://java.sun.com/jsf/facelets"
    	xmlns:h="http://java.sun.com/jsf/html"
    	xmlns:f="http://java.sun.com/jsf/core"
    	xmlns:c="http://java.sun.com/jstl/core">
    <body>
    <h1>Testfrom (Schritt 2)</h1>
    <h:form>
    	<p>Vorname: #{flowScope.person.firstname}</p>
    	<p>Nachname: #{flowScope.person.surname}</p>
    	<p>Telefon: #{flowScope.person.phonenumber}</p>
    
    	<h:commandButton value="previous" action="previous"></h:commandButton>
    </h:form>
    </body>
    </html>
    phonebook-servlet-config.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:flow="http://www.springframework.org/schema/webflow-config"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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/context
    		http://www.springframework.org/schema/context/spring-context-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">
    
    
    	<!--
    		==================================================================
    		Spring MVC stuff
    		==================================================================
    	-->
    
    	<!-- This activates post-processors for annotation-based config -->
    	<!-- http://www.infoq.com/articles/spring-2.5-part-1 -->
    	<context:annotation-config />
    
    	<context:component-scan base-package="phonebook" />
    
    	<!-- Enables POJO @Controllers (like CartController) -->
    	<bean
    		class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
    
    	<!-- Maps flow requests from DispatcherServlet to flowController -->
    	<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    		<property name="mappings">
    			<value>
    				/*.htm=flowController
    			</value>
    		</property>
    		<property name="alwaysUseFullPath" value="true" />
    	</bean>
    
    	<!--
    		Enables annotated methods on POJO @Controllers (like CartController)
    	-->
    	<bean
    		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
    
    	<!-- Enables plain Controllers (e.g. FlowController) -->
    	<bean
    		class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
    
    	<!-- Maps a logical view name to a physical resource -->
    	<bean id="viewResolver"
    		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="prefix" value="/WEB-INF/pages/" />
    		<property name="suffix" value=".xhtml" />
    	</bean>
    
    
    	<!--
    		==================================================================
    		Spring Web Flow stuff
    		==================================================================
    	-->
    
    	<!--
    		Using FlowController instead of FlowHandlers; see SWF Reference Guide,
    		section 9.5.
    	-->
    	<bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">
    		<property name="flowExecutor" ref="flowExecutor" />
    	</bean>
    
    	<flow:flow-executor id="flowExecutor" flow-registry="flowRegistry" />
    
    	<!-- This creates an XmlFlowRegistryFactory bean -->
    	<flow:flow-registry id="flowRegistry"
    		flow-builder-services="flowBuilderServices">
    		<flow:flow-location-pattern value="/WEB-INF/flows/*-flow.xml" />
    	</flow:flow-registry>
    	<flow:flow-builder-services id="flowBuilderServices"
    		view-factory-creator="viewFactoryCreator" />
    
    	<bean id="viewFactoryCreator"
    		class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
    		<property name="viewResolvers">
    			<list>
    				<ref bean="viewResolver" />
    			</list>
    		</property>
    	</bean>
    	<!--
    		==================================================================
    		Spring Faces stuff
    		==================================================================
    	-->
    	<!--
    		<flow:flow-registry id="flowRegistry"
    		flow-builder-services="facesFlowBuilderServices">
    		<flow:flow-location-pattern value="/WEB-INF/flows/*-flow.xml" />
    		</flow:flow-registry> <faces:flow-builder-services
    		id="facesFlowBuilderServices" />
    	-->
    </beans>

  • #2
    I looked your config files and I found some issues:

    1. The configuration of DispatcherServlet in the web.xml file is different from the configuration in the reference documentation .

    2. In then phonebook-servlet-config.xml file you use '/*.htm' to maps flow requests. Why?.

    This is the configuration used in the swf-booking-faces example application where main and booking are flows:

    Code:
    	<!-- Maps request URIs to controllers -->			
    	<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    		<property name="mappings">
    			<value>
    				/main=flowController
    				/booking=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>

    Comment


    • #3
      Thank you for your informations ;-)

      1.
      I changed my web.xml so that it looks like in the reference.
      But now I always get the following message:

      HTTP Status 404
      type Status report
      message /phonebook/phonebook-flow.htm
      description The requested resource (/phonebook/phonebook-flow.htm) is not available.

      2.
      I configured my servlet-config that way because I want to map "http://localhost:8080/phonebook/phonebook-flow.htm" to the webflow "phonebook-flow". This already works (also with faces in the flow) but as I mentioned all events/actions don't work.
      So everytime I click on the next-button the page will be realoaded instead of showing me the next view-state in the flow.

      best regards

      Comment

      Working...
      X