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 * Demonstrates:
41 * <ul>
42 * <li>How to use Action-Messages under Velocity</li>
43 * <li>How to go back to the input form</li>
44 * </ul>
45 *
46 * @author <a href="mailto:wolff@struts-it.de">Manfred Wolff</a>
47 * @since JDK 1.4
48 * @version $Revision: 1.11 $
49 *
50 */
51 public class LogonAction extends StrutsitActionBase implements StrutsitAction {
52
53
54 private static Log log = LogFactory.getLog(LogonAction.class);
55
56 /***
57 * Execute-Methods for Struts-It Actions.
58 *
59 * @param context The Context for this usecase
60 * @return true, if the request is fulfilled. In this case the context has
61 * to return the next step. False, if the request is not fulfilled
62 * yet.
63 */
64 public boolean execute(StrutsitContext context) throws Exception {
65
66
67 HibernateContext hibContext = (HibernateContext) context;
68
69
70 Service service = getService("org.struts.velocity.demo.service.LoginService");
71
72
73 hibContext.setAction(Constants.LOGIN_COMPARE_PASSWD);
74
75
76 service.execute(hibContext);
77
78 if (hibContext.getResult() == false) {
79 ActionMessages messages = new ActionMessages();
80 messages.add("", new ActionMessage("error.nameOrPassword"));
81
82 hibContext.resetForm();
83 saveMessages(hibContext.getRequest(), messages);
84
85 setInput(context);
86 } else {
87 setSucceeded(context);
88 }
89 hibContext.resetForm();
90 hibContext.release();
91 return true;
92 }
93
94 /***
95 * Gets the corresponded use case for this action.
96 *
97 * @return
98 */
99 public String getUseCase() {
100 return ("login");
101 }
102 }
103