1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package org.struts.velocity.demo.login;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.apache.struts.action.ActionMessage;
31 import org.apache.struts.action.ActionMessages;
32 import org.struts.velocity.demo.util.Constants;
33 import org.strutsit.architecture.context.StrutsitContext;
34 import org.strutsit.architecture.hibernate.HibernateContext;
35 import org.strutsit.architecture.service.Service;
36 import org.strutsit.architecture.struts.StrutsitAction;
37 import org.strutsit.architecture.struts.StrutsitActionBase;
38
39 /***
40 * <p>
41 * The accountaction is called, when the user will create a new account for
42 * himself. First it looks if the account already exists. In this case an error
43 * message will provide. In the other case a new account will be created and a
44 * message will be sendet to the new user.
45 * </p>
46 * <p>
47 * Demonstrates:
48 * <ul>
49 * <li>How to use Action-Messages under Velocity.</li>
50 * <li>How to go back to the input form.</li>
51 * </ul>
52 * </p>
53 *
54 * @author <a href="mailto:wolff@struts-it.de">Manfred Wolff</a>
55 * @since JDK 1.4
56 * @version $Revision: 1.15 $
57 */
58 public class AccountAction extends StrutsitActionBase implements StrutsitAction {
59
60
61 private static Log log = LogFactory.getLog(AccountAction.class);
62
63 /***
64 * Execute-Methods for Struts-It Actions.
65 *
66 * @param context The Context for this usecase
67 * @return true, if the request is fulfilled. In this case the context has
68 * to return the next step. False, if the request is not fulfilled
69 * yet.
70 */
71 public boolean execute(StrutsitContext context) throws Exception {
72
73 if (log.isTraceEnabled()) {
74 log.trace("execute -> START");
75 }
76
77 HibernateContext hibContext = (HibernateContext) context;
78
79
80 Service service = getService("org.struts.velocity.demo.service.LoginService");
81
82
83 hibContext.setAction(Constants.LOGIN_ACOUNT_EXISTS);
84
85
86 service.execute(hibContext);
87
88 boolean result = hibContext.getResult();
89
90
91 if (result == true) {
92 ActionMessages errors = new ActionMessages();
93 errors.add("", new ActionMessage("account.error.exists"));
94
95 saveMessages(hibContext.getRequest(), errors);
96 setInput(context);
97
98 if (log.isTraceEnabled()) {
99 log.trace("execute with input -> END");
100 }
101 return true;
102 }
103
104
105 hibContext.setAction(Constants.LOGIN_NEW_ACOUNT);
106 service.execute(hibContext);
107
108
109 hibContext.resetForm();
110 hibContext.release();
111
112 setSucceeded(context);
113
114 if (log.isTraceEnabled()) {
115 log.trace("execute with success -> END");
116 }
117 return true;
118 }
119
120 /***
121 * The use-case for the usecase driven approuch.
122 */
123 public String getUseCase() {
124 return "login";
125 }
126 }