Spring MVC Custom Validator
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd" >
|
||||
|
||||
<beans
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/mvc
|
||||
http://www.springframework.org/schema/mvc/spring-mvc.xsd
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd">
|
||||
<mvc:annotation-driven />
|
||||
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
|
||||
</beans>
|
||||
@@ -0,0 +1,38 @@
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
|
||||
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Sample Form</title>
|
||||
<style>
|
||||
body { background-color: #eee; font: helvetica; }
|
||||
#container { width: 500px; background-color: #fff; margin: 30px auto; padding: 30px; border-radius: 5px; }
|
||||
.green { font-weight: bold; color: green; }
|
||||
.message { margin-bottom: 10px; }
|
||||
label {width:70px; display:inline-block;}
|
||||
input { display:inline-block; margin-right: 10px; }
|
||||
form {line-height: 160%; }
|
||||
.hide { display: none; }
|
||||
.error { color: red; font-size: 0.9em; font-weight: bold; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="container">
|
||||
|
||||
<h2>Phone Number</h2>
|
||||
<c:if test="${not empty message}"><div class="message green">${message}</div></c:if>
|
||||
|
||||
<form:form action="/spring-mvc-java/addValidatePhone" modelAttribute="validatedPhone">
|
||||
|
||||
<label for="phoneInput">Phone: </label>
|
||||
<form:input path="phone" id="phoneInput" />
|
||||
<form:errors path="phone" cssClass="error" />
|
||||
<br/>
|
||||
|
||||
<input type="submit" value="Submit" />
|
||||
</form:form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user