spring-webflow icon indicating copy to clipboard operation
spring-webflow copied to clipboard

Improve locating/loading of flow resources [SWF-1683]

Open spring-operator opened this issue 9 years ago • 1 comments

Johannes Grimm opened SWF-1683 and commented

In a scenario where I have two flows (abstract-flow and example-flow) and example-flow inherits from abstract-flow the resources defined in of abstract-flow can not be resolved if it is located in a different folder than example-flow.

Let's make the example more explicit. We have our files arranged like in the following tree:

\---webapp
    \---WEB-INF
        \---flows
            +---abstract-flow
                +---abstract-flow.xml
                +---abstract-flow-beans.xml
                \---abstract-view.xhtml
            \---example-flow
                +---example-flow.xml
                \---example-view.xhtml

And the files have the following content:

<?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"
    abstract="true">

    <view-state id="abstract-view" />
    
    <global-transitions>
        <transition on="abstract-view" to="abstract-view" />
    </global-transitions>
    
    <bean-import resource="abstract-flow-beans.xml" />
</flow>
<beans xmlns="http://www.springframework.org/schema/beans" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/aop
                           http://www.springframework.org/schema/aop/spring-aop.xsd
                           http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/util 
                           http://www.springframework.org/schema/util/spring-util-2.5.xsd">

    <util:list id="abstractList">
        <value>One</value>
        <value>Two</value>
        <value>Three</value>
    </util:list>
    
</beans>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
    <title>abstract-flow: abstract-view</title>
</h:head>
<h:body>
    <h:form>
        <h1>abstract-flow: abstract-view</h1>
    </h:form>
</h:body>
</html>
<?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"
    parent="abstract-flow"
    start-state="example-view">

    <view-state id="example-view" />
    
</flow>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
    <title>example-flow: example-view</title>
</h:head>
<h:body>
    <h:form>
        <h1>example-flow: example-view</h1>
        
        <div>
            <strong>abstractList: </strong>#{abstractList}
        </div>
        
        <h:commandButton value="Show abstract-view" action="abstract-view" />
    </h:form>
</h:body>
</html>

If one tries to access the example-flow of this configuration an exception will be raised indicating that some resources were not found. (I know this behavior is documented but wouldn't it be nice to have this working?)

The modifications in [^patch.diff] ensure that the resources will be loaded relative to the defining flow. A complete and working example is included as [^resource-location.zip]. This project already contains the patched webflow classes.


Affects: 2.4.2

Attachments:

spring-operator avatar Feb 26 '16 13:02 spring-operator

Rossen Stoyanchev commented

Seems reasonable.

spring-operator avatar Feb 26 '16 15:02 spring-operator