我正在努力为我的Spring WebFlow设置验证。验证工作正常,但我无法显示错误消息。该流程成功地绑定到order.customer模型(并设置其字段),但仅此而已。我不认为我应该手动捕获验证异常,但如果我不这样做,流程崩溃。除了基本的jsr-303验证之外,我还使用了hibernate验证器。我还想验证表单而不先尝试将其保存到数据库。 这是流量: 结帐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 name="order" required="true"/>
<view-state id="collectCustomerInfo" view="collectCustomerInfo.jsp" model="order">
<transition on="customerInfoCollected" to="customerReady" />
<transition on="cancel" to="cancel"/>
</view-state>
<end-state id="cancel" />
<end-state id="customerReady" />
</flow>
客户flow.xml
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset="utf-8">
<link rel="stylesheet"
href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<title>Customer</title>
</head>
<body>
<section>
<div class="jumbotron">
<div class="container">
<h1>Customer</h1>
<p>Customer details</p>
</div>
</div>
</section>
<section class="container">
<form:form modelAttribute="order.customer" class="form-horizontal">
<fieldset>
<legend>Customer Details</legend>
<form:errors path="*" cssClass="alert alert-danger" element="div"/>
<div class="form-group">
<label class="control-label col-lg-2" for="name"><spring:message code="editCustomer.form.name.label"/></label>
<div class="col-lg-10">
<form:input id="name" path="name" type="text" class="form:input-large"/>
<form:errors path="name" cssClass="text-danger"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2" for="surname"><spring:message code="editCustomer.form.surname.label"/></label>
<div class="col-lg-10">
<form:input id="surname" path="surname" type="text" class="form:input-large"/>
<form:errors path="surname" cssClass="text-danger"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2" for="streetName"><spring:message code="editCustomer.form.streetName.label"/></label>
<div class="col-lg-10">
<div class="form:input-prepend">
<form:input id="streetName" path="streetName" type="text" class="form:input-large"/>
<form:errors path="streetName" cssClass="text-danger"/>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2" for="doorNo"><spring:message code="editCustomer.form.doorNo.label"/></label>
<div class="col-lg-10">
<div class="form:input-prepend">
<form:input id="doorNo" path="doorNo" type="text" class="form:input-large"/>
<form:errors path="doorNo" cssClass="text-danger"/>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2" for="zipCode"><spring:message code="editCustomer.form.zipCode.label"/></label>
<div class="col-lg-10">
<div class="form:input-prepend">
<form:input id="zipCode" path="zipCode" type="text" class="form:input-large"/>
<form:errors path="zipCode" cssClass="text-danger"/>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2" for="areaName"><spring:message code="editCustomer.form.areaName.label"/></label>
<div class="col-lg-10">
<div class="form:input-prepend">
<form:input id="areaName" path="areaName" type="text" class="form:input-large"/>
<form:errors path="areaName" cssClass="text-danger"/>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2" for="state"><spring:message code="editCustomer.form.state.label"/></label>
<div class="col-lg-10">
<div class="form:input-prepend">
<form:input id="state" path="state" type="text" class="form:input-large"/>
<form:errors path="state" cssClass="text-danger"/>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2" for="country"><spring:message code="editCustomer.form.country.label"/></label>
<div class="col-lg-10">
<div class="form:input-prepend">
<form:input id="country" path="country" type="text" class="form:input-large"/>
<form:errors path="country" cssClass="text-danger"/>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2" for="phoneNumber"><spring:message code="editCustomer.form.phoneNumber.label"/></label>
<div class="col-lg-10">
<div class="form:input-prepend">
<form:input id="phoneNumber" path="phoneNumber" type="text" class="form:input-large"/>
<form:errors path="phoneNumber" cssClass="text-danger"/>
</div>
</div>
</div>
<input type="hidden" name="_flowExecutionKey" value="${flowExecutionKey}"/>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<input type="submit" id="btnAdd" class="btn btn-primary"
value="Add" name="_eventId_customerInfoCollected" />
<button id="btnCancel" class="btn btn-default" name="_eventId_cancel">Cancel</button>
</div>
</div>
</fieldset>
</form:form>
</section>
</body>
</html>
collectCustomerInfo.jsp
@Entity
@Table(name="Customers")
public class Customer implements Serializable{
private static final long serialVersionUID = 7565769627033046336L;
@Id
@Column(name = "CustomerID", unique = true, nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer customerId;
@Email
@Column(name = "Email", nullable = false, length = 60)
//can not duplicate emails in database
@CustomerEmail
@Size(min = 3, max = 60, message = "{Size.Customer.email.validation}")
private String email;
@NotNull
@Column(name = "Password", nullable = false, length = 60)
@Size(min = 5, max = 60, message = "{Size.Customer.password.validation}")
private String password;
@Size(min = 3, max = 50, message = "{Size.Customer.name.validation}")
@Column(name = "Name", length = 30)
private String name;
@Size(min = 3, max = 50, message = "{Size.Customer.surname.validation}")
@Column(name = "Surname", length = 30)
private String surname;
@Column(name = "StreetName", length = 50)
private String streetName;
@Column(name = "DoorNo")
private String doorNo;
@Column(name = "AreaName", length = 20)
private String areaName;
@Column(name = "State", length = 50)
private String state;
@Column(name = "Country", length = 25)
private String country;
@Column(name = "ZipCode", length = 10)
private String zipCode;
@Pattern(regexp="(^$|[0-9]{9})")
@Column(name = "PhoneNumber", nullable = false, length = 15)
private String phoneNumber;
Customer.java
ConvertAll
有关如何以正确的方式完成此任务的提示吗?