I am learning Spring WebFlow and I'm stuck with a strange problem:
The <view-state>
tag allows a "model"
attribute. So I would expect that in the JSP I can accept the object passed in this model using the attribute "modelAttribute"
in my Spring form (just like in "normal" Spring MVC I would do the same in a Controller class).
But the behaviour I see is very strange: The JSP is being rendered, but it is calling ONLY the getter method on my object and NEVER the setter!
Detailed description of the behaviour see below.
So here is some code: My 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="funkCLass" class="somepackage.FlowFunctions"/>
<view-state id="two_buttons" model="funkClass">
<transition on="wayChosen" to="decider"/>
</view-state>
<action-state id="decider">
<evaluate expression="funkCLass.getButtonNumber()"/>
<transition on = "1" to="way_one"/>
<transition on = "2" to="way_two"/>
</action-state>
<view-state id="way_one"/>
<view-state id="way_two"/>
</flow>
My JSP which is being rendered in the view-state (only the <form:form>
tag). I read in a book that I need the hidden input here to make the flow somehow continue where it stopped after leaving the JSP - but for me the behaviour is the same with and without this input.
<form:form modelAttribute="funkCLass" method="POST">
Select your way, Sir: <form:input path="buttonNumber"/>
<br/><br/>
<input type="hidden" name="_flowExecutionKey" value="${flowExecutionKey}"/>
<input type="submit" name="wayChosen" value="Submit"/>
</form:form>
The class FlowFunctions (quite simple):
import java.io.Serializable;
public class FlowFunctions implements Serializable {
private int buttonNumber;
public void printMessage(){
System.out.println("Hello World OF Spring Web Flow!");
}
public int getButtonNumber() {
System.out.println("Inside getButtonNumber()");
return buttonNumber;
}
public void setButtonNumber(int buttonNumber) {
System.out.println("Inside setButtonNumber()");
this.buttonNumber = buttonNumber;
}
}
So the behaviour is: When I call the flow's URL in the browser, I enter the view state and I see the JSP, this works fine. At the moment when I enter it, I see in the console, that the getter method for the field buttonNumber is called - this is also as expected. But when I enter a value into the input field and click Submit, the setter method is NOT called! (I see this by the println-statements in the getter and setter). Also the JSP is immediately rendered again so, I guess there is also no "wayChosen" request parameter being send on submit, otherwise the transition to the next state should execute?
Can you explain me, what is the reason for this behaviour and how can I make it work?