SWF-1419 Add ability to plug in custom Spring Validator via FlowBuilderServices to support JSR-303 validation
This commit is contained in:
@@ -21,12 +21,12 @@
|
||||
|
||||
<dependencies>
|
||||
<!-- core dependencies -->
|
||||
<dependency org="javax.xml.bind" name="com.springsource.javax.xml.bind" rev="2.2.0" conf="compile->runtime" />
|
||||
<dependency org="com.sun.xml" name="com.springsource.com.sun.xml.bind" rev="2.2.0" conf="compile->runtime" />
|
||||
<dependency org="javax.persistence" name="com.springsource.javax.persistence" rev="1.0.0" conf="compile->runtime"/>
|
||||
<dependency org="javax.servlet" name="com.springsource.javax.servlet" rev="2.4.0" conf="provided->runtime"/>
|
||||
<dependency org="javax.servlet" name="com.springsource.javax.servlet.jsp.jstl" rev="1.2.0" conf="compile->runtime"/>
|
||||
<dependency org="javax.transaction" name="com.springsource.javax.transaction" rev="1.1.0" conf="compile->runtime"/>
|
||||
<dependency org="javax.xml.bind" name="com.springsource.javax.xml.bind" rev="2.2.0" conf="compile->runtime" />
|
||||
<dependency org="org.apache.log4j" name="com.springsource.org.apache.log4j" rev="1.2.15" conf="compile->runtime"/>
|
||||
<dependency org="org.hibernate" name="com.springsource.org.hibernate" rev="3.2.6.ga" conf="compile->runtime"/>
|
||||
<dependency org="org.hibernate" name="com.springsource.org.hibernate.annotations" rev="3.3.0.ga" conf="compile->runtime"/>
|
||||
|
||||
@@ -38,17 +38,12 @@ public class Booking implements Serializable {
|
||||
|
||||
private Hotel hotel;
|
||||
|
||||
@NotNull
|
||||
private Date checkinDate;
|
||||
|
||||
@Future
|
||||
@NotNull
|
||||
private Date checkoutDate;
|
||||
|
||||
@Pattern(regexp = "[0-9]{16}", message = "is not a 16 digit card number")
|
||||
private String creditCard;
|
||||
|
||||
@NotEmpty
|
||||
private String creditCardName;
|
||||
|
||||
private int creditCardExpiryMonth;
|
||||
@@ -68,6 +63,7 @@ public class Booking implements Serializable {
|
||||
this.hotel = hotel;
|
||||
this.user = user;
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
||||
setCheckinDate(calendar.getTime());
|
||||
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
||||
setCheckoutDate(calendar.getTime());
|
||||
@@ -99,6 +95,8 @@ public class Booking implements Serializable {
|
||||
|
||||
@Basic
|
||||
@Temporal(TemporalType.DATE)
|
||||
@Future
|
||||
@NotNull
|
||||
public Date getCheckinDate() {
|
||||
return checkinDate;
|
||||
}
|
||||
@@ -127,6 +125,8 @@ public class Booking implements Serializable {
|
||||
|
||||
@Basic
|
||||
@Temporal(TemporalType.DATE)
|
||||
@Future
|
||||
@NotNull
|
||||
public Date getCheckoutDate() {
|
||||
return checkoutDate;
|
||||
}
|
||||
@@ -135,6 +135,7 @@ public class Booking implements Serializable {
|
||||
this.checkoutDate = checkoutDate;
|
||||
}
|
||||
|
||||
@Pattern(regexp = "[0-9]{16}", message = "{invalidCreditCardPattern}")
|
||||
public String getCreditCard() {
|
||||
return creditCard;
|
||||
}
|
||||
@@ -166,6 +167,7 @@ public class Booking implements Serializable {
|
||||
this.beds = beds;
|
||||
}
|
||||
|
||||
@NotEmpty
|
||||
public String getCreditCardName() {
|
||||
return creditCardName;
|
||||
}
|
||||
@@ -202,11 +204,11 @@ public class Booking implements Serializable {
|
||||
public void validateEnterBookingDetails(ValidationContext context) {
|
||||
MessageContext messages = context.getMessageContext();
|
||||
if (checkinDate.before(today())) {
|
||||
messages.addMessage(new MessageBuilder().error().source("checkinDate").code(
|
||||
"booking.checkinDate.beforeToday").build());
|
||||
messages.addMessage(new MessageBuilder().error().source("checkinDate")
|
||||
.code("booking.checkinDate.beforeToday").build());
|
||||
} else if (checkoutDate.before(checkinDate)) {
|
||||
messages.addMessage(new MessageBuilder().error().source("checkoutDate").code(
|
||||
"booking.checkoutDate.beforeCheckinDate").build());
|
||||
messages.addMessage(new MessageBuilder().error().source("checkoutDate")
|
||||
.code("booking.checkoutDate.beforeCheckinDate").build());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
# Custom messages for JSR-303 validation
|
||||
invalidCreditCardPattern=is not a valid 16 digit card number.
|
||||
@@ -4,9 +4,9 @@
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/tx
|
||||
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
|
||||
http://www.springframework.org/schema/tx/spring-tx.xsd">
|
||||
|
||||
<!-- Instructs Spring to perfrom declarative transaction management on annotated classes -->
|
||||
<tx:annotation-driven />
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
xmlns:security="http://www.springframework.org/schema/security"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/security
|
||||
http://www.springframework.org/schema/security/spring-security-3.0.xsd">
|
||||
http://www.springframework.org/schema/security/spring-security.xsd">
|
||||
|
||||
<!-- Configure Spring Security -->
|
||||
<security:http auto-config="true" use-expressions="true">
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<!-- Scans for application @Components to deploy -->
|
||||
<context:component-scan base-package="org.springframework.webflow.samples.booking" />
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
xmlns:webflow="http://www.springframework.org/schema/webflow-config"
|
||||
xmlns:faces="http://www.springframework.org/schema/faces"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd
|
||||
http://www.springframework.org/schema/faces http://www.springframework.org/schema/faces/spring-faces-2.0.xsd">
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config.xsd
|
||||
http://www.springframework.org/schema/faces http://www.springframework.org/schema/faces/spring-faces.xsd">
|
||||
|
||||
<!-- Executes flows: the central entry point into the Spring Web Flow system -->
|
||||
<webflow:flow-executor id="flowExecutor">
|
||||
<webflow:flow-executor id="flowExecutor">
|
||||
<webflow:flow-execution-listeners>
|
||||
<webflow:listener ref="facesContextListener"/>
|
||||
<webflow:listener ref="jpaFlowExecutionListener" />
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:faces="http://www.springframework.org/schema/faces"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/faces http://www.springframework.org/schema/faces/spring-faces-2.0.xsd">
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/faces http://www.springframework.org/schema/faces/spring-faces.xsd">
|
||||
|
||||
<faces:resources />
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<h:selectOneMenu id="pageSize" value="#{searchCriteria.pageSize}">
|
||||
<f:selectItems value="#{referenceData.pageSizeOptions}" />
|
||||
</h:selectOneMenu>
|
||||
<p:commandButton id="findHotels" value="Find Hotels" action="search" update="@form" />
|
||||
<p:commandButton id="findHotels" value="Find Hotels" action="search" update="@form" ajax="false" />
|
||||
</h:panelGrid>
|
||||
<p:tooltip for="searchString" targetPosition="topRight" position="bottomLeft"
|
||||
value="Search hotels by name, address, city, or zip." style="cream" />
|
||||
|
||||
Reference in New Issue
Block a user