0
votes

i´m trying to setup a JSF application with Spring Web Flow.

I´m using Spring 3.1 Spring faces 2.3.1 JSF (api,impl) 2.1.6

My problem is the following that the program is not taking the correct location of my jsf views.

I have found some tutorials like

or http://dgparsons.org/jsf-and-spring-webflow.html for integrating jsf and spring web flow.

In one of these view resolving is done with:

<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/views" />
<property name="suffix" value=".xhtml" />
</bean>

And so I put my xhtml files in the folder /WEB-INF/views/

My Flow is in the directory /WEB-INF/config/flow/start.flow

When I gave it a try the program always wants to open the start.xhtml from the folder /WEB-INF/config/flow/start.xhtml

So it seems it is completly ignoring the UrlBasedViewResolver.

My FlowBuilderServices is configured as following:

<beans:bean id="flowBuilderServices"
    class="org.springframework.webflow.engine.builder.support.FlowBuilderServices">
...
<beans:property name="viewFactoryCreator"> 
       <beans:bean
         class="org.springframework.faces.webflow.JsfViewFactoryCreator" /> 
     </beans:property>

...
 </beans:bean>

In the tutorials there is no JsfViewFactoryCreator and I cant find a tutorial about it.

As from the javadoc JsfViewFactoryCreator/JsfViewFactory is responsible for the RESTORE_VIEW phase. So I dived into the source code of the getView() Method of the JsfViewFactory.

JsfViewFactory.java

In line 105

UIViewRoot viewRoot = viewHandler.restoreView(facesContext, viewName);

a FlowViewHandler is called, which generates the wrong path relative to the path of my flow files.

resourcePath = resolveResourcePath(RequestContextHolder.getRequestContext(), viewId);

So my question is now. How can I associate the UrlBasedViewResolver correctly with the flowRegistry/flowbuilderservices so that it takes /WEB-INF/views/*.xthml as my path to the xhtml files.

Or if it is maybe old fashioned to use UrlBasedViewResolver (as I didnt see it in the spring web flow documentation for jsf) how can the webflow beans be configured correctly to use the directories i defined.

For completeness here is my webflow-config.xml file

<!-- Executes flows: the central entry point into the Spring Web Flow system -->
  <flow-executor id="flowExecutor">
    <flow-execution-listeners>
      <listener ref="facesContextListener" />
      <listener ref="securityListener" />
    </flow-execution-listeners>
  </flow-executor>

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

  <beans:bean id="flowBuilderServices"
    class="org.springframework.webflow.engine.builder.support.FlowBuilderServices">
    <beans:property name="expressionParser">
      <beans:bean
        class="org.springframework.webflow.expression.el.WebFlowELExpressionParser">
        <beans:constructor-arg>
          <beans:bean class="com.sun.el.ExpressionFactoryImpl" />
        </beans:constructor-arg>
      </beans:bean>
    </beans:property>
    <beans:property name="viewFactoryCreator"> 
       <beans:bean
         class="org.springframework.faces.webflow.JsfViewFactoryCreator" /> 
     </beans:property>
    <beans:property name="conversionService">
      <beans:bean
        class="org.springframework.binding.convert.service.DefaultConversionService">
      </beans:bean>
    </beans:property>
  </beans:bean>
1
Can you try, prefix property <property name="prefix" value="/WEB-INF/views/" /> instead of <property name="prefix" value="/WEB-INF/views" /> ?Sazzadur Rahaman
I tried that, but doesnt make a difference. Problem is that the ViewResolver cannot be attached to the JsfViewFactoryCreator. If I would use a MvcViewFactoryCreator I could add a viewresolver. But there isnt a setter for that in the JsfViewFactoryCreator. Seems to me that there is no alternative to place the xhtml file directly there were the flow.xml file is. which doesnt make really sense for me.Logarith

1 Answers

1
votes

So finally I found the way to it myself and it was quite simple.

As written in the documentation of spring webflow under - Specifying view identifiers Spring Webflow Documentation

the solution is to use an absolute view identifier in the flow definition:

<view-state id="enterBookingDetails" view="/WEB-INF/hotels/booking/bookingDetails.xhtml">

Thus there is no need for a URLBasedViewResolver or a special configuration of JSFViewFactoryCreator.