KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > test > UserValidator


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.test;
8
9
10 import java.util.Map JavaDoc;
11
12 import com.inversoft.error.BasicError;
13 import com.inversoft.verge.mvc.controller.Action;
14 import com.inversoft.verge.mvc.validator.Validator;
15 import com.inversoft.verge.util.RequestContext;
16 import com.inversoft.verge.util.WebBeanProperty;
17
18
19 /**
20  * <p>
21  * This class is the user validator
22  * </p>
23  *
24  * @author Brian Pontarelli
25  * @since 2.0
26  * @version 2.0
27  */

28 public class UserValidator implements Validator {
29
30     public static boolean handled = false;
31     public static boolean validated = false;
32
33     /**
34      * Handles the invalid age conversion
35      */

36     public void handleConversion(Object JavaDoc model, WebBeanProperty property, Action action) {
37         handled = true;
38         // no op
39
}
40
41     /**
42      * Handles the normal validation
43      */

44     public boolean validate(Map JavaDoc modelObjects, Action action) {
45         validated = true;
46
47         Customer customer = (Customer) modelObjects.get("customer");
48         RequestContext context = action.getRequestContext();
49         if (customer.getFirstName() == null || customer.getLastName() == null) {
50             context.addError(new BasicError("Need a name dude"));
51         }
52
53         if (customer.getAddress() == null ||
54                 customer.getAddress().getCity() == null ||
55                 customer.getAddress().getState() == null ||
56                 customer.getAddress().getAddress1() == null ||
57                 customer.getAddress().getZipcode() == null) {
58             context.addError(new BasicError("Need an address dude"));
59         }
60
61         return !context.hasErrors();
62     }
63 }
Popular Tags