Portlet Development: Let’s go!
Posted in Uncategorized on December 27th, 2009 by admin – Comments OffIn this article I want to give you some of the basics about portlet development and standards around it, so we can make some cool examples afterwards.
Portal, Portlet, Portlet Container
It’s important to know the difference between this 3 terms.
The Portal is the overall application. You can think of a Portal as a web application running on a server. It can provide personalization for all or some portlets and all other portal functionality.
A portlet is a small portion of a page inside the portal. Much of it’s API looks the same as servlets, as we see later. But the big difference is that a servlet generates a complete html page, where a portlet only generates a part of it, so no <html>-tag there!
A portlet container runs and manages the lifecycle of the portal.
API
The first standarized Portal API (1.0) is based on JSR-168. The current version is 2.0, based on JSR-286, and is rather complete when it comes to functionality. We gonna talk about this last version the most.
I will explain the differences during the examples to keep things clear.
Portlets are like Serlvets
To keep things simple, portlets are much the same as servlets. If you already know something about Servlets (and I recommand that), porting your knowledge to portlets will be easy.
- Just like Servlets implement the Servlet interface, Portlets implement the Portlet Interface.
- The portlet API also has a GenericPortlet.
- Where servlets have servletrequests/servletresponses, portlets have portletrequests/portletresponses.
Well, I think you get the idea.
Portlets are not like Servlets
It would be too easy for us developers, if everything was the same for both. As you can see in the API, portlets do not extend from servlets. In fact, they are really different internally! They just kept the
names in the same way to let you feel comfortable and to prevent any confusion.
- As I told before, portlets never generate a complete html-page. They are inside a portal page.
- A portlet has a portlet mode. There are 3 modes: VIEW, EDIT and HELP, where VIEW is the default. I’ll make you understand this in the examples.
- Portlets are more complex. Developers agree that developing portlets is more complex then developing servlets.
Where a ServletRequest is always a HttpServletRequest, a PortletRequest can be an EventRequest, an ActionRequest, a RenderRequest or even a ResourceRequest.
It’s like comparing men and women, where the men are the straightforward servlets and the women are the refined portlets. But unlike with women, you can play with several portlets at the same time!
Because you have several portlets at the same page, there can be interaction between portlets, and when you want to refresh a portlet, you actually refresh all portlets on that page.