%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ page session="false" %>
Flow definitions are typically authored in XML documents. A flow is typically packaged in its own directory inside /WEB-INF, and co-located with its dependent resources such as page templates and message resources. For example, the tutorial flow you are using right now lives in the /WEB-INF/tutorial directory along with its JSP page templates.
XML is a good format for expressing structure. Since a flow definition primarily captures the navigation structure between your pages, XML is a good fit. XML is not an appropriate for general programming. This is why your flows should invoke actions written in Java or Groovy to carry out application behaviors.
<html> <head> <title>Hello world!</title> </head> <h1> Hello world! </h1> </html>
<transition on="submit" to="page2" />Then define your page2 view-state:
<view-state id="page2"> </view-state>And the corresponding page2.jsp:
<html> <head> <title>Hello world!</title> </head> <h1> This is page 2! </h1> </html>Finally, create a button on your start.jsp that raises the submit event to trigger the state transition:
<form method="post"> <input type="submit" name="_eventId_submit" value="Submit" /> </form>Click the button and you should be taken to page 2.
Web flow excels at implementing dynamic navigation logic that takes a user through different paths based on what they enter or who they are.
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <html> <head> <title>Hello world!</title> </head> <h1> Hello world! </h1> <form:form method="post" modelAttribute="helloWorldForm"> <form:checkbox path="selected" /> <input type="submit" name="_eventId_submit" value="Submit" /> </form:form> </html>
package org.springframework.webflow.samples.helloworld;
import java.io.Serializable;
public class HelloworldForm implements Serializable {
private boolean selected = true;
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
}
<var name="helloWorldForm" class="org.springframework.webflow.samples.helloworld.HelloWorldForm" />Then update your start view-state to use this variable as its data model, enabling automatic model binding and validation:
<view-state id="start" model="helloWorldForm"> ...
Refresh your flow and the checkbox should render checked since the default value for the HelloWorldForm.selected property is true. Uncheck the box and submit and go back in your browser and the unchecked status should be preserved.
<view-state id="start">
<transition on="submit" to="isSelected" />
</view-state>
<decision-state id="isSelected">
<if test="helloWorldForm.selected" then="page2" else="page3" />
</decision-state>
...
<view-state id="page3">
</view-state>
Click the button with the checkbox selected and you should be taken to page2.
Click the button with the checkbox de-selected and you should be taken to page3 (you'll need to create a JSP or you'll get a 404).
<input type="submit" name="_eventId_finish" value="Finish" />In your start view-state, declare the finish transition:
<transition on="finish" to="finished" />And finally define the end-state:
<end-state id="finished" view="externalRedirect:welcome" />Click the Finish button and you should be taken back to the application welcome screen.