Chapter 13. Reusable logic with portlet filters

 

This chapter covers

  • Types of portlet filters
  • The portlet filter lifecycle
  • Creating portlet filters
  • Configuring portlet filters

In previous chapters you saw examples where the complete request-processing logic was contained within the lifecycle methods of the portlet. For instance, in the Book Catalog portlet, the logic that sets the title of the portlet window, based on the value of the myaction request parameter, is part of the request-processing logic. Similarly, you can have request-logging logic in lifecycle methods that log requests to a log file, which is later analyzed by a log-analyzer tool to generate important statistics. The logic inside a lifecycle method can’t be used by other portlets, because it’s tightly coupled with the portlet class, so you can’t reuse the logic to programmatically set the portlet title and to log requests.

A portlet filter is a reusable component that allows you to write request- and response-processing logic that can be applied to multiple portlets and that can be reused in different portlet applications with just a few configuration steps. A portlet filter is similar to a servlet filter, and it’s responsible for preprocessing requests before they’re handled by the portlet and for postprocessing responses before they’re sent to the portal server.

13.1. Types of portlet filters

13.2. Portlet filter interface methods and lifecycle

13.3. Using portlet filters with the Book Catalog portlet

13.4. Setting the portlet title with the portlet filter

13.5. Validating requests with portlet filters

13.6. Converting text to hyperlinks with portlet filters

13.7. Filter chaining

13.8. Summary