1 package example; 2 3 import java.io.IOException ; 4 import java.io.PrintWriter ; 5 6 import javax.portlet.*; 7 8 public class HelloWorldPortlet extends GenericPortlet { 9 10 private String _view = "/hello.jsp"; 11 12 15 public void setView(String view) 16 { 17 _view = view; 18 } 19 20 public void init(PortletConfig portletConfig) 21 throws PortletException 22 { 23 super.init(portletConfig); 24 25 String p = getInitParameter("view"); 26 if (p != null) 27 setView(p); 28 } 29 30 public void processAction(ActionRequest request, ActionResponse response) 31 throws PortletException, IOException 32 { 33 PortletMode mode = request.getPortletMode(); 34 35 if (mode.equals(PortletMode.EDIT)) { 36 37 39 String identity = request.getParameter("identity"); 40 String color = request.getParameter("color"); 41 42 44 response.setRenderParameter("identity", identity); 45 response.setRenderParameter("color", color); 46 47 49 response.setPortletMode(PortletMode.VIEW); 50 } 51 } 52 53 63 protected void prepareObjects(RenderRequest request, RenderResponse response) 64 { 65 String identity = request.getParameter("identity"); 66 if (identity == null) 67 identity = "World"; 68 69 String color = request.getParameter("color"); 70 if (color == null) 71 color = "silver"; 72 73 request.setAttribute("identity", identity); 74 request.setAttribute("color", color); 75 } 76 77 80 protected void dispatch( RenderRequest request, 81 RenderResponse response, 82 String path ) 83 throws PortletException, IOException 84 { 85 PortletContext ctx = getPortletContext(); 86 PortletRequestDispatcher dispatcher = ctx.getRequestDispatcher(path); 87 dispatcher.include(request, response); 88 } 89 90 93 public void render(RenderRequest request, RenderResponse response) 94 throws PortletException, IOException 95 { 96 prepareObjects(request, response); 97 dispatch(request, response, _view); 98 } 99 100 public void destroy() 101 { 102 } 103 } 104 105 106 | Popular Tags |