title: Spring Web Flow - JSF - PrimeFaces Integration : UrlBasedViewResolver adds incorrect URL on JSF action
body: <p><strong>UrlBasedViewResolver prefix is appended to the URL multiple times so that the resouces are not found.</strong></p>
  
  <p>Spring Version: 4.2.0.RELEASE   Spring Web Flow Version:
     2.4.2.RELEASE   PrimeFaces: 5.2 JSF (jsf-api and jsf-impl): 2.2.12</p>
  
  <pre><code>&lt;servlet-mapping&gt; 
          &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt; 
          &lt;url-pattern&gt;/app/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
  &lt;context-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;/WEB-INF/applicationContext.xml&lt;/param-value&gt;
          &lt;/context-param&gt;
  
  
  
  &lt;context-param&gt; 
              &lt;param-name&gt;facelets.DEVELOPMENT&lt;/param-name&gt;
              &lt;param-value&gt;true&lt;/param-value&gt; 
          &lt;/context-param&gt;
  
  
   &lt;context-param&gt;
              &lt;param-name&gt;javax.faces.FACELETS_REFRESH_PERIOD&lt;/param-name&gt;
              &lt;param-value&gt;1&lt;/param-value&gt;
          &lt;/context-param&gt;
  
  
  
  
  &lt;context-param&gt;
          &lt;param-name&gt;javax.faces.FACELETS_LIBRARIES&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/springsecurity.taglib.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
  
  
  
  
  
  &lt;servlet&gt;
          &lt;servlet-name&gt;FacesServlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
  
  
   &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;FacesServlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt;
          &lt;url-pattern&gt;*.jsf&lt;/url-pattern&gt;
           &lt;url-pattern&gt;*.faces&lt;/url-pattern&gt;
           &lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
  
  
  
      &lt;context-param&gt;
          &lt;param-name&gt;javax.faces.DEFAULT_SUFFIX&lt;/param-name&gt;
          &lt;param-value&gt;.xhtml&lt;/param-value&gt;
      &lt;/context-param&gt; 
  
  
  
      &lt;filter&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
          &lt;async-supported&gt;true&lt;/async-supported&gt;
      &lt;/filter&gt;
  
  
  
  
      &lt;filter-mapping&gt;
              &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
              &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
               &lt;dispatcher&gt;FORWARD&lt;/dispatcher&gt;
              &lt;dispatcher&gt;REQUEST&lt;/dispatcher&gt;
          &lt;/filter-mapping&gt; 
  
  
  
  
  
       &lt;listener&gt;
              &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
          &lt;/listener&gt;
  
  
  
  
  
  &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.request.RequestContextListener&lt;/listener-class&gt;
      &lt;/listener&gt; 
  </code></pre>
  
  <p><strong>WebConfig.java</strong></p>
  
  <pre><code>@Configuration
      public class WebConfig{
  
      @Autowired
      private SpringWebFlowConfig webFlowConfig;
  
  
      @Bean
      public FlowHandlerMapping flowHandlerMapping() {
          FlowHandlerMapping mapping = new FlowHandlerMapping();
          mapping.setOrder(1);
          mapping.setFlowRegistry(this.webFlowConfig.flowRegistry());
          mapping.setDefaultHandler(new UrlFilenameViewController());
          return mapping;
      }
  
      @Bean
      public FlowHandlerAdapter flowHandlerAdapter() {
          JsfFlowHandlerAdapter adapter = new JsfFlowHandlerAdapter();
          adapter.setFlowExecutor(this.webFlowConfig.flowExecutor());
          adapter.setSaveOutputToFlashScopeOnRedirect(true);
          return adapter;
      }
  
  
      @Bean
      public UrlBasedViewResolver faceletsViewResolver() {
          UrlBasedViewResolver resolver = new UrlBasedViewResolver();
          resolver.setViewClass(JsfView.class);
          resolver.setPrefix("/WEB-INF/jsfaces/");
          resolver.setSuffix(".xhtml");
          return resolver;
      }
  
  
  
      @Bean
      public SimpleControllerHandlerAdapter simpleControllerHandlerAdapter() {
          return new SimpleControllerHandlerAdapter();
      }
  
  
  }
  </code></pre>
  
  <p><strong>SpringWebFlowConfig.java</strong></p>
  
  <pre><code>@Configuration
  public class SpringWebFlowConfig extends AbstractFacesFlowConfiguration{
  
      @Bean
      public FlowExecutor flowExecutor() {
          return getFlowExecutorBuilder(flowRegistry())
                  .addFlowExecutionListener(new FlowFacesContextLifecycleListener())
                  .addFlowExecutionListener(new SecurityFlowExecutionListener())
                  //.addFlowExecutionListener(persistenceListener())
                  .build();
      }
  
  
     @Bean
      public FlowDefinitionRegistry flowRegistry() {
          return getFlowDefinitionRegistryBuilder(flowBuilderServices())
                  .setBasePath("/WEB-INF/flows")
                  .addFlowLocationPattern("/**/*-flow.xml")
                  .build();
      }
  
  
      @Bean
      public FlowBuilderServices flowBuilderServices() {
          return getFlowBuilderServicesBuilder().setDevelopmentMode(true).build();
      }
  
  }
  </code></pre>
  
  <p><strong>faces-config.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
      version="2.2"&gt;
  
         &lt;application&gt;
          &lt;message-bundle&gt;/messages/JsfMessageResources&lt;/message-bundle&gt;
         &lt;/application&gt; 
  
  
      &lt;application&gt;
          &lt;el-resolver&gt;org.springframework.web.jsf.el.SpringBeanFacesELResolver&lt;/el-resolver&gt;
      &lt;/application&gt;
  
  &lt;/faces-config&gt;
  </code></pre>
  
  <p><strong>mvc-dispatcher-servlet.xml</strong></p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:mvc="http://www.springframework.org/schema/mvc" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:faces="http://www.springframework.org/schema/faces"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="
          http://www.springframework.org/schema/beans     
          http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context-3.0.xsd
          http://www.springframework.org/schema/tx 
          http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
          http://www.springframework.org/schema/mvc
          http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"&gt;
  
  
  
      &lt;mvc:annotation-driven /&gt;
  
  
      &lt;context:component-scan base-package="com.efacec.oms.powr.controller" /&gt;  
  
      &lt;mvc:resources mapping="/app/resources/**" location="/resources/" /&gt;
      &lt;mvc:default-servlet-handler /&gt;
  &lt;/beans&gt;
  
  
  
  **Folder Structure**
  
  WEB-INF
   -- flows --&gt;account-flow.xml    test-flow.xml welcome-flow.xml
   -- jsfaces  --&gt; accountHome.xml   welcome.xhtml   testFlow.xml
   -- templates  --&gt; general.xhtml
  
  **welcome-flow.xml**
  </code></pre>
  
  <p><strong>welcome-flow.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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;
  
      &lt;var name="user" class="com.domain.UserEntity"/&gt;
  
  
      &lt;view-state id="welcome"  view="welcome.xhtml" model="user"&gt;
          &lt;transition on="signOn" to="authentication"&gt;
          &lt;/transition&gt; 
      &lt;/view-state&gt;
  
  
      &lt;action-state id="authentication"&gt; 
          &lt;evaluate expression="userService.authenticate(user)" /&gt;
          &lt;transition on="success" to="finish" /&gt;
          &lt;transition on="failure" to="welcome" /&gt;
      &lt;/action-state&gt;
  
  
      &lt;end-state id="finish" view="externalRedirect:account" /&gt; 
  
  &lt;/flow&gt;
  </code></pre>
  
  <p><strong>account-flow.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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;
  
  
  
      &lt;var name="uiUtils" class="com.jsf.utils.UIUtils"/&gt;
  
  
      &lt;view-state id="account" view="accountHome.xhtml"&gt;
      &lt;/view-state&gt;
  
  &lt;/flow&gt;
  </code></pre>
  
  <p><strong>JSF Event:</strong>  inside welcome.xhtml</p>
  
  <pre><code>&lt;p:commandButton id="submitButton" action="signOn"
                      value="Sign In" /&gt;
  </code></pre>
  
  <p>On clicking the button </p>
  
  <p>It adds resolver prefix multiple times("/WEB-INF/jsfaces/") in the URL so that the resources are not found</p>
  
  <p>Error encountered:</p>
  
  <pre><code>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is javax.faces.FacesException: **/WEB-INF/jsfaces/WEB-INF/jsfaces/**welcome.xhtml Not Found in ExternalContext as a Resource
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
      org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
      org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
      com.efacec.oms.powr.filter.TokenAuthenticationFilter.doFilter(TokenAuthenticationFilter.java:89)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
      org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
      org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
      org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
      org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
  </code></pre>