Spring Web Flow
  1. Spring Web Flow
  2. SWF-1319

The view path cannot be resolved if the flow is located in the classpath.

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: General Backlog
    • Component/s: JSF
    • Labels:
      None

      Description

      This may be related to http://jira.springframework.org/browse/SPR-4681 however it does not appear to be fixed in swf 2.0.1 and spring 2.5.4.

      The tomcat server that I deploy to has "unPackWars=false", therefore I keep my flows in the classpath. However, that means the view can't be resolved with a relative view path.

      I get:

      java.lang.IllegalStateException: A ContextResource is required to get relative view paths within this context
              at org.springframework.faces.webflow.JsfViewFactory.resolveViewName(JsfViewFactory.java:160)
              at org.springframework.faces.webflow.JsfViewFactory.getView(JsfViewFactory.java:84)
              at org.springframework.webflow.engine.ViewState.resume(ViewState.java:186)
              at org.springframework.webflow.engine.Flow.resume(Flow.java:535)
              at org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:261)
              at org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:153)
              at org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:173)
              at org.springframework.webflow.mvc.servlet.FlowController.handleRequest(FlowController.java:172)
              at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java
      :48)
              at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
              at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
              at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
              at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
              at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:834)
              at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:640)
              at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1286)
              at java.lang.Thread.run(Thread.java:595)
      

      My config files:

      admin-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">		
      
      	<!-- Executes flows: the central entry point into the Spring Web Flow system -->	
      	<webflow:flow-executor id="flowExecutor">
      		<webflow:flow-execution-listeners>
      			<webflow:listener ref="adminFlowExecutionListener" />
      		</webflow:flow-execution-listeners>
      	</webflow:flow-executor>
      	
      	<!-- Creates the registry of flow definitions for this application -->
      	<webflow:flow-registry id="flowRegistry" flow-builder-services="facesFlowBuilderServices">
      		<webflow:flow-location path="classpath:flows/admin/admin.xml"/>
      	</webflow:flow-registry>
      
      	<!-- Configures the Spring Web Flow JSF integration -->
      	<faces:flow-builder-services id="facesFlowBuilderServices" />
      
      </beans>
      

      admin-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">
      
      	<!-- Maps request URIs to controllers -->			
      	<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
      		<property name="mappings">
      			<props>
                      <prop key="*/admin">flowController</prop>
                  </props>
      		</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>
      
      	<!-- Handles requests mapped to the Spring Web Flow system -->
      	<bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">
      		<property name="flowExecutor" ref="flowExecutor"/>
      	</bean>
      
      	<!-- Maps logical view names to Facelet templates (e.g. 'login' to '/WEB-INF/layouts/login.xhtml' -->
      	<bean id="faceletsViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
      		<property name="viewClass" value="org.springframework.faces.mvc.JsfView"/>
      		<property name="prefix" value="/WEB-INF/layouts/" />
      		<property name="suffix" value=".xhtml" />
      	</bean>
      
      </beans>
      

      admin-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">
      	
      	<bean id="admin" class="com.phantom.client.web.application.AdminApplication" />
      	
      	<!-- Imports the configurations of the different infrastructure systems of the application -->
      	<import resource="admin-webmvc-config.xml" />
      	<import resource="admin-webflow-config.xml" />
      
      </beans>
      

      web.xml:

      <?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/config/admin-application-config.xml
      		</param-value>
      	</context-param>
      	
      	<listener>
      		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      	</listener>
      
      	<!-- 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></param-value>
      		</init-param>
      		<load-on-startup>2</load-on-startup>
      	</servlet>
      	
      	<servlet-mapping>
      		<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
      		<url-pattern>/spring/*</url-pattern>
      	</servlet-mapping>
      
      ...
      
      </web-app>
      

        Issue Links

          Activity

          Hide
          Keith Donald added a comment -

          Can you try this with the latest nightly build against Spring 2.5.5 and report if this is still an issue? We've improved logging as well in this area.

          Show
          Keith Donald added a comment - Can you try this with the latest nightly build against Spring 2.5.5 and report if this is still an issue? We've improved logging as well in this area.
          Hide
          Keith Donald added a comment -

          We have researched this and it is currently a known limitation.

          Currently, only flows located in a servlet or portlet context-relative path can load relative resources. Relative classpath flow resources are not possible at present, since the code for the JSF integration and the default MVC view->resource mapping logic is assuming the environment requires context-relative path Strings.

          We will improve this in 2.0.4 for the JSF integration by allowing a custom ViewHandler to be used to map logical view ids to resources, with no such hard coded assumptions about a ContextResource. You can already do this with MVC views by plugging in a custom FlowResourceViewResolver. See SWF-810 for this.

          As a workaround, I recommend for the time being you pack your flows and their resources inside the WAR you deploy within a WEB-INF directory there. There's still a WEB-INF even with WAR still packed.

          Show
          Keith Donald added a comment - We have researched this and it is currently a known limitation. Currently, only flows located in a servlet or portlet context-relative path can load relative resources. Relative classpath flow resources are not possible at present, since the code for the JSF integration and the default MVC view->resource mapping logic is assuming the environment requires context-relative path Strings. We will improve this in 2.0.4 for the JSF integration by allowing a custom ViewHandler to be used to map logical view ids to resources, with no such hard coded assumptions about a ContextResource. You can already do this with MVC views by plugging in a custom FlowResourceViewResolver. See SWF-810 for this. As a workaround, I recommend for the time being you pack your flows and their resources inside the WAR you deploy within a WEB-INF directory there. There's still a WEB-INF even with WAR still packed.
          Show
          Keith Donald added a comment - see http://forum.springframework.org/showthread.php?t=64252
          Hide
          Stephane Toussaint added a comment -

          Does branches 2.2.x or 3.0.x improve in any way this issue ?
          I'm not able to modularized (put flows and views in jars) the booking-faces sample for 2.2.0-RELEASE based on the workarounds found on the thread pointed by Keith.
          Must I try to work on those solutions or will another new feature leads to this point ?

          Show
          Stephane Toussaint added a comment - Does branches 2.2.x or 3.0.x improve in any way this issue ? I'm not able to modularized (put flows and views in jars) the booking-faces sample for 2.2.0-RELEASE based on the workarounds found on the thread pointed by Keith. Must I try to work on those solutions or will another new feature leads to this point ?
          Hide
          Donny A. Wijaya added a comment -

          JSF2ResourceResolver doesn't work. I experienced the same error when I tried to experiment with primefaces sample.

          Show
          Donny A. Wijaya added a comment - JSF2ResourceResolver doesn't work. I experienced the same error when I tried to experiment with primefaces sample.

            People

            • Assignee:
              Phil Webb
              Reporter:
              James ffolliott
            • Votes:
              10 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:

                Development