1 package org.springframework.samples.jpetstore.web.struts; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 import javax.servlet.http.HttpServletRequest ; 7 8 import org.apache.struts.action.ActionMapping; 9 10 import org.springframework.beans.support.PagedListHolder; 11 import org.springframework.samples.jpetstore.domain.Account; 12 13 public class AccountActionForm extends BaseActionForm { 14 15 16 17 public static final String VALIDATE_EDIT_ACCOUNT = "editAccount"; 18 public static final String VALIDATE_NEW_ACCOUNT = "newAccount"; 19 private static final ArrayList LANGUAGE_LIST = new ArrayList (); 20 21 22 23 private String username; 24 private String password; 25 private String repeatedPassword; 26 private List languages; 27 private List categories; 28 private String validate; 29 private String forwardAction; 30 private Account account; 31 private PagedListHolder myList; 32 33 34 35 static { 36 LANGUAGE_LIST.add("english"); 37 LANGUAGE_LIST.add("japanese"); 38 } 39 40 41 42 public AccountActionForm() { 43 languages = LANGUAGE_LIST; 44 } 45 46 47 48 public PagedListHolder getMyList() { return myList; } 49 public void setMyList(PagedListHolder myList) { this.myList = myList; } 50 51 public String getForwardAction() { return forwardAction; } 52 public void setForwardAction(String forwardAction) { this.forwardAction = forwardAction; } 53 54 public String getUsername() { return username; } 55 public void setUsername(String username) { this.username = username; } 56 57 public String getPassword() { return password; } 58 public void setPassword(String password) { this.password = password; } 59 60 public String getRepeatedPassword() { return repeatedPassword; } 61 public void setRepeatedPassword(String repeatedPassword) { this.repeatedPassword = repeatedPassword; } 62 63 public Account getAccount() { return account; } 64 public void setAccount(Account account) { this.account = account; } 65 66 public List getLanguages() { return languages; } 67 public void setLanguages(List languages) { this.languages = languages; } 68 69 public List getCategories() { return categories; } 70 public void setCategories(List categories) { this.categories = categories; } 71 72 public String getValidate() { return validate; } 73 public void setValidate(String validate) { this.validate = validate; } 74 75 76 77 public void doValidate(ActionMapping mapping, HttpServletRequest request, List errors) { 78 if (validate != null) { 79 if (VALIDATE_EDIT_ACCOUNT.equals(validate) || VALIDATE_NEW_ACCOUNT.equals(validate)) { 80 if (VALIDATE_NEW_ACCOUNT.equals(validate)) { 81 account.setStatus("OK"); 82 addErrorIfStringEmpty(errors, "User ID is required.", account.getUsername()); 83 if (account.getPassword() == null || account.getPassword().length() < 1 || !account.getPassword().equals(repeatedPassword)) { 84 errors.add("Passwords did not match or were not provided. Matching passwords are required."); 85 } 86 } 87 if (account.getPassword() != null && account.getPassword().length() > 0) { 88 if (!account.getPassword().equals(repeatedPassword)) { 89 errors.add("Passwords did not match."); 90 } 91 } 92 addErrorIfStringEmpty(errors, "First name is required.", this.account.getFirstName()); 93 addErrorIfStringEmpty(errors, "Last name is required.", this.account.getLastName()); 94 addErrorIfStringEmpty(errors, "Email address is required.", this.account.getEmail()); 95 addErrorIfStringEmpty(errors, "Phone number is required.", this.account.getPhone()); 96 addErrorIfStringEmpty(errors, "Address (1) is required.", this.account.getAddress1()); 97 addErrorIfStringEmpty(errors, "City is required.", this.account.getCity()); 98 addErrorIfStringEmpty(errors, "State is required.", this.account.getState()); 99 addErrorIfStringEmpty(errors, "ZIP is required.", this.account.getZip()); 100 addErrorIfStringEmpty(errors, "Country is required.", this.account.getCountry()); 101 } 102 } 103 104 } 105 106 public void reset(ActionMapping mapping, HttpServletRequest request) { 107 super.reset(mapping, request); 108 setUsername(null); 109 setPassword(null); 110 setRepeatedPassword(null); 111 } 112 113 } 114 | Popular Tags |