01 /*
02 *
03 * All content copyright Terracotta, Inc., unless otherwise indicated. All rights reserved.
04 *
05 */
06 package demo.townsend.action;
07
08 import javax.servlet.http.HttpServletRequest;
09 import javax.servlet.http.HttpServletResponse;
10 import javax.servlet.http.HttpSession;
11
12 import org.apache.struts.action.Action;
13 import org.apache.struts.action.ActionForm;
14 import org.apache.struts.action.ActionForward;
15 import org.apache.struts.action.ActionMapping;
16 import org.apache.struts.action.ActionMessage;
17 import org.apache.struts.action.ActionMessages;
18 import org.apache.struts.action.DynaActionForm;
19
20 import demo.townsend.common.Constants;
21 import demo.townsend.service.DataKeeper;
22
23 /**
24 * DisplayUserListAction processes the request to display the user's list.
25 * User's list is fetched from the HttpSession object, and a dynamic form (i.e.,
26 * displayUserListForm) is populated with this data.
27 */
28 public class DisplayUserListAction extends Action {
29 @Override
30 public ActionForward execute(ActionMapping mapping, ActionForm form,
31 HttpServletRequest request, HttpServletResponse response)
32 throws Exception {
33
34 HttpSession session = request.getSession();
35 if (session == null) {
36 ActionMessages errors = new ActionMessages();
37 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
38 "error.expired.session"));
39 saveErrors(request, errors);
40 return mapping.findForward(Constants.NO_SESSION);
41 }
42 DataKeeper dkeeper = (DataKeeper) session
43 .getAttribute(Constants.DATA_KEY);
44 if (dkeeper == null) {
45 dkeeper = new DataKeeper();
46 }
47
48 ((DynaActionForm) form).set("recentList", dkeeper.getList());
49 ((DynaActionForm) form).set("listLength", Integer.toString(dkeeper
50 .getListSize()));
51 ((DynaActionForm) form).set("currentProduct", dkeeper.getCurrent());
52
53 return mapping.findForward(Constants.SUCCESS_KEY);
54 }
55 }
|