01 /*
02 *
03 * All content copyright Terracotta, Inc., unless otherwise indicated. All rights reserved.
04 *
05 */
06 package demo.tasklist.action;
07
08 import demo.tasklist.common.Constants;
09 import demo.tasklist.service.DataKeeper;
10 import demo.tasklist.service.ErrorKeeper;
11 import javax.servlet.http.HttpServletRequest;
12 import javax.servlet.http.HttpServletResponse;
13 import javax.servlet.http.HttpSession;
14 import org.apache.struts.action.Action;
15 import org.apache.struts.action.ActionForm;
16 import org.apache.struts.action.ActionForward;
17 import org.apache.struts.action.ActionMapping;
18 import org.apache.struts.action.DynaActionForm;
19
20 /**
21 * DisplayUserListAction processes the request to display the task list.
22 * Task list is fetched from the HttpSession object, and a dynamic form
23 * (i.e., displayUserListForm) is populated with this data.
24 */
25 public class DisplayUserListAction extends Action {
26 public ActionForward execute( ActionMapping mapping, ActionForm form,
27 HttpServletRequest request, HttpServletResponse response) throws Exception {
28 HttpSession session = request.getSession();
29 ErrorKeeper errorKeeper = (ErrorKeeper) session.getAttribute(Constants.ERROR_KEY);
30 String errorMsg = errorKeeper != null ? errorKeeper.getErrorMsg() : "";
31
32 if(errorMsg == null) {
33 errorMsg = "";
34 }
35
36 DataKeeper dkeeper = (DataKeeper) session.getAttribute(Constants.DATA_KEY );
37 if (dkeeper == null) {
38 dkeeper = new DataKeeper();
39 }
40 String numTasks = Integer.toString(dkeeper.getListSize());
41
42 ((DynaActionForm)form).set( "userList", dkeeper.getList());
43 ((DynaActionForm)form).set( "numTasks", numTasks);
44 ((DynaActionForm)form).set( "errorMsg", errorMsg);
45
46 return mapping.findForward( Constants.SUCCESS_KEY );
47 }
48 }
|