![]() |
| ||||||||||||||||||||||||||||||||||
Find this tutorial in: /opt/resin/webapps/resin-doc/portlet/tutorial/basic-render
Try the Tutorial Render parameters are used to maintain state. This tutorial adds the concept of "identity" and "color" to the basic Hello World example, the identity and color are maintained as render parameters.
Just like Servlets a Portlet does not maintain state within the Portlet object. Many requests, from many different users, may be using an instance of a portlet at the same time. In this tutorial, the "identity" and "color" are two values to contain the state of the portlet. The portlet provides links to change the color or identity, and maintains the identity and color from request to request.
The value of a render parameter is obtained from the request object using request.getParameter(name).
The value of a render parameter can be changed on a subsequent request with the use of response.createRenderURL() . response.createRenderURL() returns a PortletURL . The PortletURL is used to set render parameters for the next request, the toString() method is used to generate the appropriate url.
When createRenderURL() is used to create a PortletURL which is then manipulated, parameters that are not explicitly set retain the value they have for the current request. For example, if:
A render url created like this:
Will result in a subsequent request with:
Since "identity" was not set when creating the url, it's value of "Ron" is maintained in the generated url.
The functionality described in this section is implemented in index.jsp. response.createRenderURL() can only be used from within the portlet itself. Since the PortalServlet is just a servlet, any jsp or servlet can initiate a request to a portlet using a url sent to the browser, or the forward and include mechanism available with method ServletContext.getRequestDispatcher and method ServletRequest.getRequestDispatcher . The simplest usage of the portal is to provide a straight url to it.
The functionality that is provided by portlets requires some extra work when passing parameters. The PortalContext is used to create the urls.
The PortalContext is found as an application attribute with a name that corresponds to the servlet-name used when configuring the PortalServlet. The "hello" portion of application.getAttribute("PortalContext(hello)") corresponds to the servlet-name:
| |||||||||||||||||||||||||||||||||||