1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.demo.customerInfo;
18
19 import java.io.IOException;
20 import java.util.ArrayList;
21 import java.util.GregorianCalendar;
22 import java.util.List;
23
24 import javax.portlet.ActionRequest;
25 import javax.portlet.ActionResponse;
26 import javax.portlet.PortletException;
27 import javax.portlet.PortletSession;
28 import javax.portlet.RenderRequest;
29 import javax.portlet.RenderResponse;
30
31 /***
32 * @author <a href="mailto:paulsp@apache.org">Paul Spencer</a>
33 * @version $Id: CustomerPortlet.java 516448 2007-03-09 16:25:47Z ate $
34 */
35 public class CustomerPortlet extends org.apache.portals.bridges.common.GenericServletPortlet
36 {
37
38 private List defaultCustomers = new ArrayList();
39
40 /*** Creates a new instance of CustomerPortlet */
41 public CustomerPortlet()
42 {
43 }
44
45
46 public void init() throws javax.portlet.PortletException
47 {
48 CustomerInfo newCustomer = null;
49 Address newAddress = null;
50
51
52 newCustomer = new CustomerInfo();
53 newCustomer.setName("Jane Doe");
54
55 newCustomer.setLastOrdered(new GregorianCalendar(2002,05,15));
56 newAddress = new Address();
57 newAddress.setName(newCustomer.getName());
58 newAddress.setStreet("124 Main Street");
59 newAddress.setCity("AnyTown");
60 newAddress.setState("ME");
61 newAddress.setCountry("U.S.A.");
62 newCustomer.setBillingAddress(newAddress);
63 newAddress.setName(newCustomer.getName());
64 newAddress.setStreet("1862 Elm Drive");
65 newAddress.setCity("AnyTown");
66 newAddress.setState("ME");
67 newAddress.setCountry("U.S.A.");
68 newCustomer.setShippingAddress(newAddress);
69 this.defaultCustomers.add(newCustomer);
70
71 newCustomer = new CustomerInfo();
72 newCustomer.setName("Fred Smith");
73 newCustomer.setLastOrdered(new GregorianCalendar(2002,9,15));
74 newAddress = new Address();
75 newAddress.setName(newCustomer.getName());
76 newAddress.setStreet("1 Bearch Way");
77 newAddress.setCity("AnyTown");
78 newAddress.setState("ME");
79 newAddress.setCountry("U.S.A.");
80 newCustomer.setBillingAddress(newAddress);
81 newAddress.setName(newCustomer.getName());
82 newAddress.setStreet("1862 Elm Drive");
83 newAddress.setCity("AnyTown");
84 newAddress.setState("ME");
85 newAddress.setCountry("U.S.A.");
86 newCustomer.setShippingAddress(newAddress);
87 this.defaultCustomers.add(newCustomer);
88
89 newCustomer = new CustomerInfo();
90 newCustomer.setName("Wallace George");
91 newCustomer.setLastOrdered(new GregorianCalendar(2003,1,1));
92 newAddress = new Address();
93 newAddress.setName(newCustomer.getName());
94 newAddress.setStreet("73 Wamack Drive");
95 newAddress.setCity("AnyTown");
96 newAddress.setState("ME");
97 newAddress.setCountry("U.S.A.");
98 newCustomer.setBillingAddress(newAddress);
99 newAddress.setName(newCustomer.getName());
100 newAddress.setStreet("73 Wamack Drive");
101 newAddress.setCity("AnyTown");
102 newAddress.setState("ME");
103 newAddress.setCountry("U.S.A.");
104 newCustomer.setShippingAddress(newAddress);
105 this.defaultCustomers.add(newCustomer);
106 }
107
108 /***
109 * Execute the servlet as define by the init parameter or preference PARAM_ACTION_PAGE. The value
110 * if the parameter is a relative URL, i.e. /actionPage.jsp will execute the
111 * JSP editPage.jsp in the portlet application's web app. The action should
112 * not generate any content. The content will be generate by doCustom(),
113 * doHelp() , doEdit(), or doView().
114 *
115 * See section PLT.16.2 of the JSR 168 Portlet Spec for more information
116 * around executing a servlet or JSP in processAction()
117 *
118 * @see javax.portlet.GenericPortlet#processAction
119 *
120 * @task Need to be able to execute a servlet for the action
121 * @task Need to set current customer and customer detail item
122 * in the session.
123 *
124 */
125 public void processAction(ActionRequest request, ActionResponse actionResponse) throws PortletException, IOException
126 {
127
128 }
129
130
131 /***
132 * Execute the servlet as define by the init parameter or preference PARAM_VIEW_PAGE.
133 * The value if the parameter is a relative URL, i.e. /viewPage.jsp will execute the
134 * JSP viewPage.jsp in the portlet application's web app.
135 *
136 * @see javax.portlet.GenericPortlet#doView
137 *
138 */
139 public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException
140 {
141 List customerList = null;
142
143 PortletSession portletSession = request.getPortletSession();
144 if (portletSession != null)
145 {
146 customerList = (List) portletSession.getAttribute("CustomerList", PortletSession.APPLICATION_SCOPE);
147 if (customerList == null)
148 {
149 customerList = this.defaultCustomers;
150 portletSession.setAttribute("CustomerList", this.defaultCustomers, PortletSession.APPLICATION_SCOPE);
151 }
152 }
153
154 else
155 {
156
157 System.out.println("In org.apache.demo.customerInfo.CustomerPortlet.doView() - The portletSession == null !!!!");
158 }
159
160
161 if (customerList == null)
162 {
163 customerList = this.defaultCustomers;
164 }
165
166
167 request.setAttribute("CustomerList", customerList);
168 super.doView(request, response);
169 }
170
171 }