concept RenderResponse in category java

appears as: RenderResponse, The RenderResponse, RenderResponse
Portlets in Action

This is an excerpt from Manning's book Portlets in Action.

The HelloWorldPortlet class defines the sayHello method , which accepts javax.portlet.RenderRequest and javax.portlet.RenderResponse objects as parameters. The sayHello method writes the “Hello World” message to the output stream. The getWriter() method of RenderResponse is similar to the getWriter() method of HttpServletResponse, which returns a PrintWriter object. The PrintWriter object is used by the sayHello method to write the “Hello World” character data to the response.

In real-world portlets, you’ll probably use a portlet framework, like Spring Portlet MVC (discussed in chapter 7 and 8), to build your portlets. A portlet framework is ideally suited for developing multipage portlets; it’s responsible for casting portlet requests to appropriate request types based on the request lifecycle phase. For instance, in the Spring Portlet MVC framework, if the lifecycle phase is RENDER_PHASE, the preceding code would cast the PortletRequest object to RenderRequest and the PortletResponse object to RenderResponse and then send them to the render method of the handler object.

Figure 3.6. The RenderResponse, ResourceResponse, ActionResponse, and EventResponse interfaces have a common superinterface, PortletResponse. The subinterfaces define additional fields and methods specific to the response types.

3.3.2. Generating content using RenderResponse

Portlets use RenderResponse to write content. It can also be used to set the title of a portlet and the next possible portlet modes.

In the examples that we’ve covered so far, portlet titles were either specified in the portlet deployment descriptor or the portlet resource bundle, but the Book Catalog portlet requires the portlet title to change when the Add Book form is shown to the user (see figure 3.3). This can be done by using the RenderResponse object’s setTitle method, as shown here: