KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > townsend > action > DisplayUserListAction


1 /*
2 @COPYRIGHT@
3 */

4 package demo.townsend.action;
5
6 import demo.townsend.common.Constants;
7 import demo.townsend.service.DataKeeper;
8 import javax.servlet.http.HttpServletRequest JavaDoc;
9 import javax.servlet.http.HttpServletResponse JavaDoc;
10 import javax.servlet.http.HttpSession JavaDoc;
11 import org.apache.struts.action.Action;
12 import org.apache.struts.action.ActionForm;
13 import org.apache.struts.action.ActionForward;
14 import org.apache.struts.action.ActionMapping;
15 import org.apache.struts.action.DynaActionForm;
16
17 /**
18  * DisplayUserListAction processes the request to display the user's list.
19  * User's list is fetched from the HttpSession object, and a dynamic form
20  * (i.e., displayUserListForm) is populated with this data.
21  */

22 public class DisplayUserListAction extends Action {
23    public ActionForward execute( ActionMapping mapping, ActionForm form,
24      HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
25      throws Exception JavaDoc {
26
27       HttpSession JavaDoc session = request.getSession();
28  
29       DataKeeper dkeeper = (DataKeeper) session.getAttribute(Constants.DATA_KEY );
30       
31       if(dkeeper == null) {
32         dkeeper = new DataKeeper();
33       }
34
35       ((DynaActionForm)form).set( "recentList", dkeeper.getList());
36       ((DynaActionForm)form).set( "listLength", Integer.toString(dkeeper.getListSize()));
37       ((DynaActionForm)form).set( "currentProduct", dkeeper.getCurrent());
38
39       return mapping.findForward( Constants.SUCCESS_KEY );
40   }
41 }
42
Popular Tags