DisplayUserListAction.java
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.tasklist.action;
09 
10 import demo.tasklist.common.Constants;
11 import demo.tasklist.service.DataKeeper;
12 import demo.tasklist.service.ErrorKeeper;
13 import javax.servlet.http.HttpServletRequest;
14 import javax.servlet.http.HttpServletResponse;
15 import javax.servlet.http.HttpSession;
16 import org.apache.struts.action.Action;
17 import org.apache.struts.action.ActionForm;
18 import org.apache.struts.action.ActionForward;
19 import org.apache.struts.action.ActionMapping;
20 import org.apache.struts.action.DynaActionForm;
21 
22 /**
23  *  DisplayUserListAction processes the request to display the task list. Task
24  *  list is fetched from the HttpSession object, and a dynamic form (i.e.,
25  *  displayUserListForm) is populated with this data.
26  *
27  *@author    Terracotta, Inc.
28  */
29 public class DisplayUserListAction extends Action {
30    public ActionForward execute(ActionMapping mapping, ActionForm form,
31          HttpServletRequest request, HttpServletResponse responsethrows Exception {
32       HttpSession session = request.getSession();
33       ErrorKeeper errorKeeper = (ErrorKeepersession.getAttribute(Constants.ERROR_KEY);
34       String errorMsg = errorKeeper != null ? errorKeeper.getErrorMsg() "";
35 
36       if (errorMsg == null) {
37          errorMsg = "";
38       }
39 
40       DataKeeper dkeeper = (DataKeepersession.getAttribute(Constants.DATA_KEY);
41       if (dkeeper == null) {
42          dkeeper = new DataKeeper();
43       }
44       String numTasks = Integer.toString(dkeeper.getListSize());
45 
46       ((DynaActionFormform).set("userList", dkeeper.getList());
47       ((DynaActionFormform).set("numTasks", numTasks);
48       ((DynaActionFormform).set("errorMsg", errorMsg);
49 
50       return mapping.findForward(Constants.SUCCESS_KEY);
51    }
52 }