Below is my code snippet from jsp & flow xml, while trying to submit the form my page is getting refreshed but request is not going to the server. Please assist.
Jsp
<form action="${flowExecutionUrl}" modelAttribute="employeeDto" method="post">
<div class="formButton">
<input type="hidden" name="_flowExecutionKey" value="${flowExecutionKey}" />
<input name="_eventId_nextBtn" type="submit" value="submit">
</div>
</form>
Flow xml
<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.4.xsd">
<var name="employeeDto" class="com.school.transferobjects.EmployeeDto"/>
<view-state id="employeeView" model="employeeDto" view="employee">
<transition on="nextBtn" to="createEmployee" />
</view-state>
<action-state id="createEmployee">
<evaluate
expression="employeeHelper.saveEmployee(flowRequestContext,employeeDto)"
result="flowScope.res"/>
<transition on="${flowScope.res.success=='success'}" to="student.do"/>
</action-state>
</flow>
I think eventId is not being recognized, and so when you submit by click of the button and eventId is not found, resulting in flow execution getting refreshed.
Make sure you include form tag:
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<form:form modelAttribute="yourModel" method="post">
...
</form:form>
Related
Can anybody help me understand what wrong here?
This is fragment from Spring web flow project. I create new object order and get a list of tables object from DB in tag of view state.
<?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.xsd">
<input name="order" required="true" />
<view-state id="chooseTable" model="flowScope.order">
<on-entry>
<set name="flowScope.order" value="new pizza.Order()"></set>
<evaluate expression="pizzaFlowActions.getFreeTables()"
result="viewScope.tables" />
</on-entry>
<transition on="chosenCreateOrder" to="bookedToOrder">
<evaluate expression="order.setTable(flowScope.order)" />
</transition>
<transition on="chosenNoOrder" to="booked">
<evaluate expression="order.setTable(flowScope.order)" />
</transition>
<transition on="cancel" to="cancel" />
</view-state>
<end-state id="cancel" />
<end-state id="bookedToOrder">
</end-state>
<end-state id="booked">
</end-state>
<global-transitions>
<transition on="cancel" to="cancel" />
</global-transitions>
</flow>
Jsp file with form with which object order is binded, and radiobuttons' values extracted from tables list.
<html xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:spring="http://www.springframework.org/tags"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:form="http://www.springframework.org/tags/form">
<jsp:output omit-xml-declaration="yes" />
<jsp:directive.page contentType="text/html;charset=UTF-8" />
<head>
<title>Book a table</title>
</head>
<body background = "${pageContext.request.contextPath}/resources/plan.gif">
<form:form commandName="order" class="box login">
<input type="hidden" name="_flowExecutionKey" value="${flowExecutionKey}" />
<b>Choose table: </b>
<c:forEach items="${tables}" var="place">
<form:radiobutton path="table" label="${place}" value="${place}"/>
<br></br>
<br></br>
</c:forEach>
<input type="submit" class="btnLogin" name="_eventId_chosenCreateOrder" value="Now choose Pizza" />
<input type="submit" class="btnLogin" name="_eventId_chosenNoOrder" value="Just book a table" />
<input type="submit" class="btnLogin" name="_eventId_cancel" value="Cancel" />
</form:form>
</body>
</html>
Piece of Order class
public class Order implements Serializable {
private static final Logger LOGGER = getLogger(Order.class);
private int id;
private Customer customer;
private Set<Pizza> pizzas;
private Payment payment;
private Place table;
The problem here is that after choosing any variant any time the form just reloading and nothing happens more.
Will appreciate any help and hints.
Transition is not invoked in my view-state and when I click the fogotusername link in my login page, it again lands to the login page itself. I think the webflow session is somehow lost. Any idea? Please help.
fogotUsername link in my login.jsp is below:
<a href="login.do?_eventId=fogotUsername&page=init" > <spring:message code="label.forgetUsername" /></a>
My login flow xml is below:
<?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" start-state="login">
<view-state id="login" view="tiles.login">
<transition on="fogotUsername" to="viewForgotUsername">
</transition>
<transition on="fogotPassword" to="viewForgotPassword">
</transition>
</view-state>
<view-state id="viewForgotUsername" view="tiles.forgotUsername">
</view-state>
<view-state id="viewForgotPassword" model="password" view="tiles.changePassword">
<transition on="submit" to="viewForgotUsername"/>
</view-state>
<end-state id="loginend"/>
</flow>
The link doesn't contain the flow execution URL. Try replacing your link element with the below:
<spring:message code="label.forgetUsername" />
I have main Route flow:
<view-state id="addRoute" model="route">
...
<transition on="editBlock" to="editBlock" validate="false" bind="true">
...
</transition>
</view-state>
<subflow-state id="editBlock" subflow="block">
</subflow-state>
By clicking on editBlock button I want to go over to Block Flow and edit Block.
I want to make it as Subflow.
Block Flow:
<on-start>
<set name="flowScope.id" value="requestParameters.id"/>
<evaluate expression="new java.util.ArrayList()" result="flowScope.attributes"/>
<evaluate expression="new java.util.ArrayList()" result="flowScope.visibility"/>
<set name="flowScope.folderId" value="requestParameters.folderId"/>
<set name="flowScope.path" value="requestParameters.path"/>
<evaluate expression="folderBean.treeAsMap" result="flowScope.tree" />
</on-start>
How to send parameters from the main Flow into Subflow? I need to provide 3 params:
id, folderId and path as stated above.
in your Block FLow, you can put:
<input name="id"/>
<input name="folderId"/>
<input name="path"/>
and then in your Route Flow you can use it this way:
<subflow-state id="editBlock" subflow="block">
<input name="id" value="flowScope.id"/>
<input name="folderId" value="flowScope.folderId"/>
<input name="path" value="flowScope.path"/>
</subflow-state>
also, if you call your Block Flow with parameters id=123&folderId=456&path=path then these parameters will be automatically mapped to the inputs with the same name which are set in the flowScope. So you won't need these set elements in you <on-start> anymore.
also FYI you can use <input name="visibility" type="java.util.ArrayList"/> and <input name="tree" value="folderBean.treeAsMap"/> and get rid of your <on-start> completely.
I am using spring mvc 3.0.4 and webflow 2.2.1, I config my webflow like the following:
<view-state id="createTaskDetail" model="task" view="task/createTaskDetail">
<transition on="upload" to="uploadFile" />
<transition on="revise" to="createTaskBasic" />
<transition on="publish" to="publish" />
<transition on="cancel" to="cancel" />
</view-state>
<view-state id="uploadFile" model="task" view="task/uploadFile">
<transition on="confirm" to="createTaskConfirm" >
<evaluate expression="task.processFile()"/>
</transition>
<transition on="revise" to="createTaskDetail" />
<transition on="publish" to="publish" />
<transition on="cancel" to="cancel" />
</view-state>
<view-state id="createTaskConfirm" model="task"
view="task/createTaskConfirm">
<transition on="publish" to="publish" />
<transition on="revise" to="uploadFile" />
<transition on="cancel" to="cancel" />
</view-state>
createTaskDetail is my 2nd view, when I arrived this page I can't forward or backward(When clicking button next or return or cancel). There is no js error or java exception,here is my jsp code of 2nd view:
<button type="submit" id="upload" name="_eventId_upload">next</button>
<button type="submit" name="_eventId_revise" >return</button>
<button type="submit" name="_eventId_cancel" >cancel</button>
<button type="submit" name="_eventId_publish" >publish</button>
Anyone has an idea? Thanks.
Do you have a form tag around the buttons?
<form:form modelAttribute="task">
inputs
buttons ...
</form:form>
Maybe validation errors which are not shown?
My view-state to action-state transition does not appear to be happening. In the following example, I want the view-state to transition to the action-state when the user submits the form. Pretty basic stuff. But the setA() method does not get called.
In the jsp, does the submit input element need to have a name of "_eventId", or "_eventId_submit", or is no name necessary? Or is something else wrong? What is webflow checking against when evaluating the on attribute of transition element?
<flow ... start-state="stateA">
<var name="flowBean" class="demo.webflow.WebFlowBean" />
<view-state id="stateA" view="fooView">
<transition on="submit" to="changeA" />
</view-state>
<action-state id="changeA">
<evaluate expression="flowScope.flowBean.setA(requestParameters.value)" />
...
</action-state>
JSP:
<form action="demo.htm" name="myform" id="myform" method="post">
<input type="hidden" name="_flowExecutionKey" value='<c:out value="${flowExecutionKey}"/>'/>
<input type="submit" name="????" value="Continue"/>
Found the problem, I think. I removed the action attribute from my form, and now everything works:
<form name="myform" id="myform" method="post">
I'm guessing that, by having that action URL in there, somehow I was restarting the flow with each submit.