1 7 package com.inversoft.verge.mvc.test; 8 9 10 import java.util.Map ; 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 28 public class UserValidator implements Validator { 29 30 public static boolean handled = false; 31 public static boolean validated = false; 32 33 36 public void handleConversion(Object model, WebBeanProperty property, Action action) { 37 handled = true; 38 } 40 41 44 public boolean validate(Map 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 |