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