![]() |
| |||||||||||||||||||||||||||
Find this tutorial in: /opt/resin/webapps/resin-doc/portlet/tutorial/basic-hello
Try the Tutorial The Hello, World tutorial shows the most basic portlet and its configuration in a simple browser page.
Portlets form a design pattern where a Portal servlet combines one or more component Portlets into a web page. Because the portlets are written as components, they can be cleanly written and tested. Applications which currently use many servlet includes might be more cleanly written as portlet applications. The Portal part of the pattern is a servlet which manages the portlets. In this example, the servlet is a simple "invoker" which calls a single portlet to render the page. Many applications will write their own Portal servlets, using Resin's generic portal library to handle the Portlet API. The "Hello, world" portlet requires the following configuration:
A Portlet is a class that implements class javax.portlet.Portlet . It is similar to a servlet. The HelloWorldPortlet in this tutorial sends a Hello, World message to the browser. The response to the browser is generated by the render() method, the render method generates a "view".
WEB-INF/portlets.xml configures the usage of portlet classes and assigns them a name.
Configuration in web.xml causes Resin to load the WEB-INF/portlets.xml file.
PortalServlet is a servlet that dispatches to a named portlet. The init-param specifies the name of the portlet in portlets.xml. In this way, portlets can be used as drop-in replacements for servlets.
Portlets work without modification in all portal products. The PortalServlet is a simple way to get a portlet going, and provides a convenient way to replace servlets with portlets. This approach is valuable for developers that wish to take advantage of the well defined pattern that portlets provide, without necessarily needing the more complete set of features such as sophisticated rendering and management of multiple portlets per page that a more complete portal provides.
The PortalServlet class used in this tutorial is part of the Generic Portal implementation which is released with an Apache open source license. The tutorial takes advantage of the fact that Resin can read the portlets.xml file and create the necessary objects for the PortalServlet. The reading of the portlets.xml to produce a GenericPortletContext is the only part of this tutorial that uses code outside of the generic portal package. (See Generic Portal for ideas of how to provide configuration from other application servers).
| ||||||||||||||||||||||||||||