这是为正在制作披萨的用户生成的 JSP 文件,它是另一个流程的子流程。我不明白为什么我需要至少选中一个复选框才能使提交按钮起作用。我的意思是,当检查了0个复选框时,请提交按钮将我发送回同一站点。我希望我带来了足够的信息,如果还有什么我应该补充的,写下来。
这是在哪里编码的?在 JSP 中还是流文件中的某个地方?
更新了所需的课程。
我为我的项目制作了github repo。
createPizza.jspx
<div xmlns:form="http://www.springframework.org/tags/form"
xmlns:jsp="http://java.sun.com/JSP/Page">
<jsp:output omit-xml-declaration="yes"/>
<jsp:directive.page contentType="text/html;charset=UTF-8" />
<h2>Create Pizza</h2>
<form:form commandName="pizza">
<input type="hidden" name="_flowExecutionKey"
value="${flowExecutionKey}"/>
<b>Size: </b><br/>
<form:radiobutton path="size"
label="Small (12-inch)" value="SMALL"/><br/>
<form:radiobutton path="size"
label="Medium (14-inch)" value="MEDIUM"/><br/>
<form:radiobutton path="size"
label="Large (16-inch)" value="LARGE"/><br/>
<form:radiobutton path="size"
label="Ginormous (20-inch)" value="GINORMOUS"/>
<br/>
<br/>
<b>Toppings: </b><br/>
<form:checkboxes path="toppings" items="${toppingsList}"
delimiter="<br/>"/><br/><br/>
<input type="submit" class="button" name="_eventId_addPizza" value="Continue"/>
<input type="submit" class="button" name="_eventId_cancel" value="Cancel"/>
</form:form>
</div>
订单流.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 name="order" required="true" />
<view-state id="showOrder">
<transition on="createPizza" to="createPizza" />
<transition on="checkout" to="orderCreated" />
<transition on="cancel" to="cancel" />
</view-state>
<!-- Corresponding state -->
<view-state id="createPizza" model="flowScope.pizza">
<on-entry>
<set name="flowScope.pizza"
value="new com.springinaction.pizza.domain.Pizza()" />
<evaluate result="viewScope.toppingsList" expression=
"T(com.springinaction.pizza.domain.Topping).asList()" />
</on-entry>
<transition on="addPizza" to="showOrder">
<evaluate expression="order.addPizza(flowScope.pizza)" />
</transition>
<transition on="cancel" to="showOrder" />
</view-state>
<end-state id="cancel" />
<end-state id="orderCreated" />
</flow>
披萨.java
package com.springinaction.pizza.domain;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("serial")
public class Pizza implements Serializable {
private PizzaSize size;
private List<Topping> toppings;
public Pizza() {
toppings = new ArrayList<Topping>();
size = PizzaSize.LARGE;
}
public PizzaSize getSize() {
return size;
}
public void setSize(PizzaSize size) {
this.size = size;
}
public void setSize(String sizeString) {
this.size = PizzaSize.valueOf(sizeString);
}
public List<Topping> getToppings() {
return toppings;
}
public void setToppings(List<Topping> toppings) {
this.toppings = toppings;
}
public void setToppings(String[] toppingStrings) {
for (int i = 0; i < toppingStrings.length; i++) {
toppings.add(Topping.valueOf(toppingStrings[i]));
}
}
}