Blanca Hdez
Blanca Hdez

Reputation: 3563

Spring web flow, create subflow with input field

I am starting with spring web flow, reading and following the documentation. I have created a new flow:

test-flow.xml

<?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">

    <var name="testName" class="com.project.TestView" />

    <view-state id="test">
        <on-entry>
            <set name="flowScope.name" value="testName.name" />
        </on-entry>
        <transition on="test" to="saveName"/>
    </view-state>

    <subflow-state id="subTest" subflow="testSub-flow">
        <input name="nameVar" value="name" />
        <transition to="error" />
    </subflow-state>

    <view-state id="error" />
    <end-state id="finish" />   
</flow>

And I am trying to create a testSub-flow.xml

<?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">

    <input type="String" name="nameVar" />

    <on-start>
        <evaluate expression="com.project.TestView.printSomething(nameVar)" result="flowScope.testPrint" />
    </on-start>

    <view-state id="printTest" >
        <transition on="restart" to="endSub" />
    </view-state>

    <end-state id="endSub" />

</flow>

The method called is:

@Transactional(readOnly = true)
    public String printSomething(String text){
        System.out.print(text + " this is a test");
        return text + " this is a test";
    }

I get some exception in the browser when it is loading the main flow, test-flow.xml

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing [AnnotatedAction@6ca837 targetAction = [EvaluateAction@7aed3a expression = com.project.TestView.printSomething(nameVar), resultExpression = flowScope.testPrint], attributes = map[[empty]]] in state 'null' of flow 'test' -- action execution attributes were 'map[[empty]]'

What could be the problem?? Thanks in advance.

Upvotes: 2

Views: 9247

Answers (1)

txedo
txedo

Reputation: 976

At first sight, it seems that it can not find any start-state. Try adding start-state attribute in flow tag:

    <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="test">

If that does not fix the problem, it could be that flow builder can not find a state named "saveName". The problem could be in this line:

<transition on="test" to="saveName"/>

If you want to invoke the subflow when "test" event occurs, you write "subTest" instead of "saveName" in order to call the subflow.

So, that line should be:

<transition on="test" to="subTest"/>

Also, note that you are not specifying any view for those view-states.

Hope this helps.

Upvotes: 1

Related Questions