Source Code Cross Referenced for AccountBean.java in  » J2EE » jfox » com » ibatis » jpetstore » presentation » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » jfox » com.ibatis.jpetstore.presentation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.ibatis.jpetstore.presentation;
002:
003:        import java.util.ArrayList;
004:        import java.util.Collections;
005:        import java.util.List;
006:
007:        import org.huihoo.jfox.soaf.container.ServiceFactory;
008:
009:        import com.ibatis.common.util.PaginatedList;
010:        import com.ibatis.jpetstore.domain.Account;
011:        import com.ibatis.jpetstore.service.AccountService;
012:        import com.ibatis.jpetstore.service.CatalogService;
013:        import com.ibatis.struts.ActionContext;
014:        import com.ibatis.struts.BaseBean;
015:        import com.ibatis.struts.BeanActionException;
016:
017:        public class AccountBean extends BaseBean {
018:
019:            /* Constants */
020:
021:            private AccountService accountService = (AccountService) ServiceFactory
022:                    .getInstance().getService(AccountService.class);
023:
024:            private CatalogService catalogService = (CatalogService) ServiceFactory
025:                    .getInstance().getService(CatalogService.class);
026:
027:            private static final String VALIDATE_NEW_ACCOUNT = "new";
028:
029:            private static final String VALIDATE_EDIT_ACCOUNT = "edit";
030:
031:            private static final List LANGUAGE_LIST;
032:
033:            private static final List CATEGORY_LIST;
034:
035:            /* Private Fields */
036:
037:            private Account account;
038:
039:            private String repeatedPassword;
040:
041:            private String pageDirection;
042:
043:            private String validation;
044:
045:            private PaginatedList myList;
046:
047:            private boolean authenticated;
048:
049:            /* Static Initializer */
050:
051:            static {
052:                List langList = new ArrayList();
053:                langList.add("english");
054:                langList.add("japanese");
055:                LANGUAGE_LIST = Collections.unmodifiableList(langList);
056:
057:                List catList = new ArrayList();
058:                catList.add("FISH");
059:                catList.add("DOGS");
060:                catList.add("REPTILES");
061:                catList.add("CATS");
062:                catList.add("BIRDS");
063:                CATEGORY_LIST = Collections.unmodifiableList(catList);
064:            }
065:
066:            /* Constructors */
067:
068:            public AccountBean() {
069:                account = new Account();
070:            }
071:
072:            /* JavaBeans Properties */
073:
074:            public String getUsername() {
075:                return account.getUsername();
076:            }
077:
078:            public void setUsername(String username) {
079:                account.setUsername(username);
080:            }
081:
082:            public String getPassword() {
083:                return account.getPassword();
084:            }
085:
086:            public void setPassword(String password) {
087:                account.setPassword(password);
088:            }
089:
090:            public PaginatedList getMyList() {
091:                return myList;
092:            }
093:
094:            public void setMyList(PaginatedList myList) {
095:                this .myList = myList;
096:            }
097:
098:            public String getRepeatedPassword() {
099:                return repeatedPassword;
100:            }
101:
102:            public void setRepeatedPassword(String repeatedPassword) {
103:                this .repeatedPassword = repeatedPassword;
104:            }
105:
106:            public Account getAccount() {
107:                return account;
108:            }
109:
110:            public void setAccount(Account account) {
111:                this .account = account;
112:            }
113:
114:            public List getLanguages() {
115:                return LANGUAGE_LIST;
116:            }
117:
118:            public List getCategories() {
119:                return CATEGORY_LIST;
120:            }
121:
122:            public String getPageDirection() {
123:                return pageDirection;
124:            }
125:
126:            public void setPageDirection(String pageDirection) {
127:                this .pageDirection = pageDirection;
128:            }
129:
130:            public String getValidation() {
131:                return validation;
132:            }
133:
134:            public void setValidation(String validation) {
135:                this .validation = validation;
136:            }
137:
138:            /* Public Methods */
139:
140:            public String newAccount() {
141:                try {
142:                    accountService.insertAccount(account);
143:                    account = accountService.getAccount(account.getUsername());
144:                    myList = catalogService.getProductListByCategory(account
145:                            .getFavouriteCategoryId());
146:                    authenticated = true;
147:                    repeatedPassword = null;
148:                    return "success";
149:                } catch (Exception e) {
150:                    throw new BeanActionException(
151:                            "There was a problem creating your Account Information.  Cause: "
152:                                    + e, e);
153:                }
154:            }
155:
156:            public String editAccountForm() {
157:                try {
158:                    account = accountService.getAccount(account.getUsername());
159:                    return "success";
160:                } catch (Exception e) {
161:                    throw new BeanActionException(
162:                            "There was a problem retrieving your Account Information. Cause: "
163:                                    + e, e);
164:                }
165:            }
166:
167:            public String editAccount() {
168:                try {
169:                    accountService.updateAccount(account);
170:                    account = accountService.getAccount(account.getUsername());
171:                    myList = catalogService.getProductListByCategory(account
172:                            .getFavouriteCategoryId());
173:                    return "success";
174:                } catch (Exception e) {
175:                    throw new BeanActionException(
176:                            "There was a problem updating your Account Information. Cause: "
177:                                    + e, e);
178:                }
179:            }
180:
181:            public String switchMyListPage() {
182:                if ("next".equals(pageDirection)) {
183:                    myList.nextPage();
184:                } else if ("previous".equals(pageDirection)) {
185:                    myList.previousPage();
186:                }
187:                return "success";
188:            }
189:
190:            public String signon() {
191:
192:                account = accountService.getAccount(account.getUsername(),
193:                        account.getPassword());
194:
195:                if (account == null || account == null) {
196:                    ActionContext.getActionContext().setSimpleMessage(
197:                            "Invalid username or password.  Signon failed.");
198:                    clear();
199:                    return "failure";
200:                } else {
201:                    account.setPassword(null);
202:
203:                    myList = catalogService.getProductListByCategory(account
204:                            .getFavouriteCategoryId());
205:
206:                    authenticated = true;
207:
208:                    return "success";
209:                }
210:            }
211:
212:            public String signoff() {
213:                ActionContext.getActionContext().getRequest().getSession()
214:                        .invalidate();
215:                clear();
216:                return "success";
217:            }
218:
219:            public boolean isAuthenticated() {
220:                return authenticated && account != null
221:                        && account.getUsername() != null;
222:            }
223:
224:            public void reset() {
225:                if (account != null) {
226:                    account.setBannerOption(false);
227:                    account.setListOption(false);
228:                }
229:            }
230:
231:            public void clear() {
232:                account = new Account();
233:                repeatedPassword = null;
234:                pageDirection = null;
235:                myList = null;
236:                authenticated = false;
237:            }
238:
239:            public void validate() {
240:                ActionContext ctx = ActionContext.getActionContext();
241:                if (validation != null) {
242:                    if (VALIDATE_EDIT_ACCOUNT.equals(validation)
243:                            || VALIDATE_NEW_ACCOUNT.equals(validation)) {
244:                        if (VALIDATE_NEW_ACCOUNT.equals(validation)) {
245:                            account.setStatus("OK");
246:                            validateRequiredField(account.getUsername(),
247:                                    "User ID is required.");
248:                            if (account.getPassword() == null
249:                                    || account.getPassword().length() < 1
250:                                    || !account.getPassword().equals(
251:                                            repeatedPassword)) {
252:                                ctx
253:                                        .addSimpleError("Passwords did not match or were not provided.  Matching passwords are required.");
254:                            }
255:                        }
256:                        if (account.getPassword() != null
257:                                && account.getPassword().length() > 0) {
258:                            if (!account.getPassword().equals(repeatedPassword)) {
259:                                ctx.addSimpleError("Passwords did not match.");
260:                            }
261:                        }
262:                        validateRequiredField(account.getFirstName(),
263:                                "First name is required.");
264:                        validateRequiredField(account.getLastName(),
265:                                "Last name is required.");
266:                        validateRequiredField(account.getEmail(),
267:                                "Email address is required.");
268:                        validateRequiredField(account.getPhone(),
269:                                "Phone number is required.");
270:                        validateRequiredField(account.getAddress1(),
271:                                "Address (1) is required.");
272:                        validateRequiredField(account.getCity(),
273:                                "City is required.");
274:                        validateRequiredField(account.getState(),
275:                                "State is required.");
276:                        validateRequiredField(account.getZip(),
277:                                "ZIP is required.");
278:                        validateRequiredField(account.getCountry(),
279:                                "Country is required.");
280:                    }
281:                }
282:
283:            }
284:
285:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.