01: package test;
02:
03: import javax.portlet.GenericPortlet;
04: import javax.portlet.ActionRequest;
05: import javax.portlet.RenderRequest;
06: import javax.portlet.ActionResponse;
07: import javax.portlet.RenderResponse;
08: import javax.portlet.PortletException;
09: import javax.portlet.PortletURL;
10: import javax.portlet.PortletMode;
11: import javax.portlet.PortletPreferences;
12: import javax.portlet.WindowState;
13:
14: import java.io.IOException;
15: import java.io.PrintWriter;
16: import java.io.InputStream;
17:
18: import java.util.Map;
19: import java.util.HashMap;
20: import java.util.Iterator;
21: import java.util.Collections;
22:
23: public class PrefPortlet extends GenericPortlet {
24:
25: public void processAction(ActionRequest request,
26: ActionResponse response) throws PortletException {
27:
28: String name = request.getParameter("NAME");
29:
30: try {
31: PortletPreferences pref = request.getPreferences();
32: pref.setValue("name", name);
33: pref.store();
34: } catch (Exception e) {
35: throw new PortletException(e.getMessage());
36: }
37: response.setPortletMode(PortletMode.VIEW);
38: response.setWindowState(WindowState.NORMAL);
39: }
40:
41: public void doView(RenderRequest request, RenderResponse response)
42: throws PortletException, IOException {
43:
44: PortletPreferences pref = request.getPreferences();
45: String name = pref.getValue("name", "");
46:
47: response.setContentType(request.getResponseContentType());
48: PrintWriter writer = response.getWriter();
49: writer.write("Hello " + name);
50: }
51:
52: public void doEdit(RenderRequest request, RenderResponse response)
53: throws PortletException, IOException {
54:
55: PortletURL actionURL = response.createActionURL();
56:
57: response.setContentType(request.getResponseContentType());
58: PrintWriter writer = response.getWriter();
59: writer.write("<form method=\"post\" action=\""
60: + actionURL.toString());
61: writer
62: .write("\"><TABLE WIDTH=\"100%\"><TR><TD ALIGN=\"RIGHT\" VALIGN=\"TOP\">name:</TD><TD ALIGN=\"LEFT\"><INPUT TYPE=\"TEXT\" NAME=\"NAME\"></TD></TR><TR><TD ALIGN=\"RIGHT\"> </TD><TD ALIGN=\"LEFT\"><INPUT TYPE=\"SUBMIT\" NAME=\"SUB1\" VALUE=\"Submit\"></TD></TR></TABLE></form>");
63: }
64:
65: }
|