KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > samples > jpetstore > web > struts > AccountActionForm


1 package org.springframework.samples.jpetstore.web.struts;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5
6 import javax.servlet.http.HttpServletRequest JavaDoc;
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   /* Constants */
16
17   public static final String JavaDoc VALIDATE_EDIT_ACCOUNT = "editAccount";
18   public static final String JavaDoc VALIDATE_NEW_ACCOUNT = "newAccount";
19   private static final ArrayList JavaDoc LANGUAGE_LIST = new ArrayList JavaDoc();
20
21   /* Private Fields */
22
23   private String JavaDoc username;
24   private String JavaDoc password;
25   private String JavaDoc repeatedPassword;
26   private List JavaDoc languages;
27   private List JavaDoc categories;
28   private String JavaDoc validate;
29   private String JavaDoc forwardAction;
30   private Account account;
31   private PagedListHolder myList;
32
33   /* Static Initializer */
34
35   static {
36     LANGUAGE_LIST.add("english");
37     LANGUAGE_LIST.add("japanese");
38   }
39
40   /* Constructors */
41
42   public AccountActionForm() {
43     languages = LANGUAGE_LIST;
44   }
45
46   /* JavaBeans Properties */
47
48   public PagedListHolder getMyList() { return myList; }
49   public void setMyList(PagedListHolder myList) { this.myList = myList; }
50
51   public String JavaDoc getForwardAction() { return forwardAction; }
52   public void setForwardAction(String JavaDoc forwardAction) { this.forwardAction = forwardAction; }
53
54   public String JavaDoc getUsername() { return username; }
55   public void setUsername(String JavaDoc username) { this.username = username; }
56
57   public String JavaDoc getPassword() { return password; }
58   public void setPassword(String JavaDoc password) { this.password = password; }
59
60   public String JavaDoc getRepeatedPassword() { return repeatedPassword; }
61   public void setRepeatedPassword(String JavaDoc repeatedPassword) { this.repeatedPassword = repeatedPassword; }
62
63   public Account getAccount() { return account; }
64   public void setAccount(Account account) { this.account = account; }
65
66   public List JavaDoc getLanguages() { return languages; }
67   public void setLanguages(List JavaDoc languages) { this.languages = languages; }
68
69   public List JavaDoc getCategories() { return categories; }
70   public void setCategories(List JavaDoc categories) { this.categories = categories; }
71
72   public String JavaDoc getValidate() { return validate; }
73   public void setValidate(String JavaDoc validate) { this.validate = validate; }
74
75   /* Public Methods */
76
77   public void doValidate(ActionMapping mapping, HttpServletRequest JavaDoc request, List JavaDoc 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 JavaDoc request) {
107     super.reset(mapping, request);
108     setUsername(null);
109     setPassword(null);
110     setRepeatedPassword(null);
111   }
112
113 }
114
Popular Tags