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