The portlet implements the rendering for each mode with a
doMODE(RenderRequest request, RenderResponse response)
render method prepares objects common to the views,
stores them as request attributes, and then calls the appropriate
prepareObjects() method prepares objects in common to the
views and stores them as request attributes. This avoids duplication of code,
and also anticipates a time when the view might be rendered using JSP. The JSP
can easily access the prepared objects because they are stored as request
In this simple example, the prepared objects are Strings. Real benefits are seen when more complex objects are prepared, for example a render parameter might indicate a primary key that is used to retrieve information from a database; objects containing that data are prepared in prepareObjects() and available for display by the view.
mode is maintained from request
to request. A url link can cause the mode of the portlet to switch.
In this tutorial, the
doView presents a url that switches to the
The action handles the form submit. In this case, only the "edit" mode supports actions.
Once the form is submitted the mode is switched to "view" and the users sees
the information that was just entered.
processAction() switches to the "view" mode using
If a call to setPortletMode() is not made, then the mode is maintained for the call to render(). In this example, if the setPortletMode(PortletMode.VIEW) call was omitted, then the render() that followed the processAction() would still have a mode of "edit".
PortletMode.VIEW, PortletMode.EDIT, PortletMode.HELP are constants for the three standard modes specified by the portlet specification. A portlet can also have any number of custom modes.
A custom PortletMode java object is created with a String argument to the constructor: