1 package xpetstore.web.struts.action.customer; 2 3 import javax.servlet.http.HttpServletRequest ; 4 5 import org.apache.struts.action.ActionErrors; 6 import org.apache.struts.action.ActionMapping; 7 8 import xpetstore.domain.customer.ejb.Customer; 9 import xpetstore.domain.signon.ejb.Account; 10 11 import xpetstore.web.struts.action.*; 12 13 14 20 public class CustomerForm 21 extends BaseForm 22 { 23 25 private Customer _customer = new Customer( ); 26 27 29 public CustomerForm( ) 30 { 31 _customer.setAccount( new Account( ) ); 32 } 33 34 36 public ActionErrors validate( ActionMapping mapping, 37 HttpServletRequest request ) 38 { 39 ActionErrors errors = new ActionErrors( ); 40 41 Account account = getCustomer( ).getAccount( ); 42 String userId = account.getUserId( ); 43 String passwd = account.getPassword( ); 44 checkNotEmpty( userId, "userId_required", errors ); 45 checkLength( userId, 4, "userId_length", errors ); 46 checkNotEmpty( passwd, "password_required", errors ); 47 checkLength( passwd, 4, "password_length", errors ); 48 49 checkNotEmpty( _customer.getEmail( ), "email_required", errors ); 50 checkNotEmpty( _customer.getCreditCardType( ), "ccType_required", errors ); 51 checkNotEmpty( _customer.getCreditCardNumber( ), "ccNumber_required", errors ); 52 checkNotEmpty( _customer.getCreditCardExpiryDate( ), "ccExpiryDate_required", errors ); 53 checkCreditCardDateFormat( _customer.getCreditCardExpiryDate( ), "ccExpiryDate_bad_format", errors ); 54 55 return errors; 56 } 57 58 public Customer getCustomer( ) 59 { 60 return _customer; 61 } 62 63 public void setCustomer( Customer customer ) 64 { 65 _customer = customer; 66 } 67 } 68 | Popular Tags |