01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
14: */
15:
16: package sample.contact;
17:
18: import org.springframework.validation.Errors;
19: import org.springframework.validation.Validator;
20:
21: /**
22: * Validates {@link WebContact}.
23: *
24: * @author Ben Alex
25: * @version $Id: WebContactValidator.java 1740 2006-11-14 02:30:00Z benalex $
26: */
27: public class WebContactValidator implements Validator {
28: //~ Methods ========================================================================================================
29:
30: public boolean supports(Class clazz) {
31: return clazz.equals(WebContact.class);
32: }
33:
34: public void validate(Object obj, Errors errors) {
35: WebContact wc = (WebContact) obj;
36:
37: if ((wc.getName() == null) || (wc.getName().length() < 3)
38: || (wc.getName().length() > 50)) {
39: errors.rejectValue("name", "err.name",
40: "Name 3-50 characters is required. *");
41: }
42:
43: if ((wc.getEmail() == null) || (wc.getEmail().length() < 3)
44: || (wc.getEmail().length() > 50)) {
45: errors.rejectValue("email", "err.email",
46: "Email 3-50 characters is required. *");
47: }
48: }
49: }
|