concept render method in category java

This is an excerpt from Manning's book Portlets in Action.
At
, the @RenderMode annotation for the sayHello method informs the Java runtime that the sayHello method is the portlet’s render method in VIEW mode (we’ll come back to this in chapter 2).
If the @RequestMapping annotated handler methods provide flexibility with method arguments and return types, they also add a little bit of confusion to the process of distinguishing a handler class’s render methods from its action methods. The simplest way to distinguish your render and action methods from each other is by passing RenderRequest or RenderResponse arguments to your render method, and ActionRequest or ActionResponse arguments to your action method, and keeping the return type of the action method as void.
Your action method must be defined to return void. Any other return type will result in an error. A common misconception is that an @RequestMapping annotated method that returns void is an action method, but that’s incorrect because you may have a render method that returns void and yet accepts a RenderResponse object as an argument to write directly to the output stream. For example, the following method is a render method, not an action method:
In listing 8.14, the showAddBookForm method is the render method that’s invoked when the user clicks the Add Book button on the home page of the Book Catalog portlet. The getCommandObject method is annotated with @ModelAttribute, so it will be invoked before the handler invokes an action or render method. The getCommandObject creates a new Book object that’s stored in the Model object with an attribute named book, which means a new command object is created before the render request is received by the AddBookController class.
You earlier saw that the @RequestMapping annotation makes it a bit difficult to distinguish render methods from action methods in annotated controllers. Spring 3.0 introduced the @RenderMapping annotation, which is used to specify a handler method as a render method. @RenderMapping is a method-level annotation that maps render requests to a handler class’s render methods. You can still use the @RequestMapping annotation to annotate your render methods, but using the @RenderMapping annotation is recommended.