Skip to content

Commit

Permalink
evolve(mvc): form validation - number range with min, max
Browse files Browse the repository at this point in the history
  • Loading branch information
chengcyber committed Jul 28, 2018
1 parent 8e5a2fe commit 85f3c03
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@

The customer is confirmed: ${ customer.firstName } ${ customer.lastName }

<br />

Free passes: ${ customer.freePasses }

</body>
</html>
5 changes: 5 additions & 0 deletions spring-mvc-demo/WebContent/WEB-INF/view/customer-form.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ Fill out the form. Asterisk(*) means required.

<br />

Free passes: <form:input path="freePasses" />
<form:errors path="freePasses" cssClass="error" />

<br />

<input type="submit" value="submit" />

</form:form>
Expand Down
14 changes: 14 additions & 0 deletions spring-mvc-demo/src/com/luv2code/springdemo/mvc/Customer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.luv2code.springdemo.mvc;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

Expand All @@ -10,6 +12,10 @@ public class Customer {
@NotNull(message="is required")
@Size(min=1, message="is required")
private String lastName;

@Min(value=0, message="must be greater than or equal to zero")
@Max(value=10, message="must be less than or equal to 10")
private int freePasses;

public String getFirstName() {
return firstName;
Expand All @@ -27,4 +33,12 @@ public void setLastName(String lastName) {
this.lastName = lastName;
}

public int getFreePasses() {
return freePasses;
}

public void setFreePasses(int freePasses) {
this.freePasses = freePasses;
}

}

0 comments on commit 85f3c03

Please sign in to comment.