Thursday, January 24, 2008

Portlet Tutorial - Deploying your first portlet to OpenPortal Portlet Container 2.0

This post is a part of the Portlet 2.0 (JSR 286) Tutorial series


At the time of this writing, only Sun seems to have a functional JSR 286 portlet container. Apache Pluto 2.0 is work in progress and I have been unsuccessful in running the Exo Portlet Container.


The OpenPortal portlet container is Sun Microsystem's implementation of the JSR 286 spec. Here is how you would deploy the Hello World portlet to this container.

Step 1 :

Get JDK 5 or greater: http://java.sun.com/javase/downloads/index.jsp

Step 2 :

Get the Glassfish Application Server or Tomcat
If you downloaded Glassfish, set it up first.

Step 3 :

Download the latest stable release of the portlet container.

Step 4 :

Follow the install instructions: Installing the Portlet Container

Step 5:

Start your server and access the portlet container at http://localhost:8080/portletdriver

Step 6:

Once you have the portlet container running, you will notice two tabs. A Portlets tab and an Admin tab.The Portlets tab helps view all the portlets currently deployed. The Admin tab is used to to deploy/undeploy portlets. You are most likely to see a blank page. This is because no portlets are deployed by default.

Click on the Admin tab and proceed to deploy the portlet.


















Once you click on deploy, the portlet is automatically deployed and configured. Click on the Portlets tab to now view the portlet.












You have successfully run your first portlet !

Wednesday, January 16, 2008

Good Javascript resources

If you are planning to learn javascript or in the process of doing so, here are some pointers.

The best way to start is to watch a series of videos presentations from YUI Theater. These videos are brilliant with absolutely high quality content.

You can watch the videos in this order:


  1. The Javascript Programming Language


  2. Advanced Javascript


  3. The Theory of DOM


  4. Javascript: The Goood Stuff

  5. High Performance Javascript

  6. The State of Ajax

  7. High Performance Ajax


The YUI Theater also offers all the content downloadable in an ipod compatible format.

Other good online resources include The w3schools Ajax Tutorial and Sun's Java Ajax Blueprints.

If you are planning to buy a book then you can consider JavaScript: The Definitive Guide or the new book in the Head First series: Head First JavaScript (Head First) .

If you would like to keep updated with the latest in the javascript/ajax world, I would recommend Ajaxian.

Tuesday, January 15, 2008

Portlet Tutorial - Anatomy of a portlet

This post is a part of the Portlet 2.0 (JSR 286) Tutorial series

Now that we have written and successfully deployed our Hello World portlet, let's understand it's various components.Here is how our portlet would look when deployed in a container.


Notice how the portal has created a distinct boundary or window for our portlet. This is called a Portlet Window. Each portlet is visually contained in a portlet window. In addition to the portlet content (i.e the "Hello Portlet 2.0 World" message that we printed in the render method), the portlet window also contains the portlet title (we mentioned this in the portlet.xml) and some click-able controls called decorations. These decorations help control two different aspects of a portlet - modes and window states.

Portlet Modes and Portlet Window States

At any given point in time, all portlets can defined by in terms of two unique characteristics - what the portlet is currently doing and how much space the portlet is taking up on the page. The Portlet Mode defines what the portlet is currently doing. The Portlet Window State defines how much space a portlet takes up in a particular page.

For example, we could have written a help message for the Hello World Portlet and displayed it when a user clicks on the Help button (the decoration with a "?" symbol). In this case the portlet would be in the "Help" mode. Similarly we could have written different "Hello World" messages based on how much space the portlet occupies on the page. This is possible because in each case, the portlet would be associated with different window states.

Monday, January 7, 2008

Portlet Tutorial - Hello Portlet 2.0 World

This post is a part of the Portlet 2.0 (JSR 286) Tutorial series

As explained in the previous post, a portlet is a pluggable component that can be run inside any compliant portal server. Here is an example of a portlet running inside a portal.


Note how the portlet occupies only a part of the portal page. This is the primary difference between a portlet and a servlet. A portlet is meant to occupy only a part of the web page. And a portal web page consists of multiple, different portlets.

Now, let's learn to write a simple Hello World Portlet. The Portlet API defines an interface called javax.portlet.Portlet. Any portlet you write must implement this interface. One easy way to do so is to extend the javax.portlet.GenericPortlet class. The GenericPortlet already implements the Portlet interface and it is strongly recommended that you always inherit GenericPortlet while writing your own portlets.

Here is our code.


public class HelloWorldPortlet extends GenericPortlet{

public void render(RenderRequest request, RenderResponse response)
throws PortletException, IOException{

response.setContentType("text/html");
response.getWriter().write("Hello Portlet 2.0 World");
}
}

We have overridden only one method of the GenericPortlet interface called render.We will look into the render method in detail in a subsequent blog post. For the time being you can assume that whenever your portlet is "shown" on the portal page, the render method is called.

Since portlets are extended components of a regular web application, they can also be packaged along with your servlets and JSPs in a war file. However you will need a separate descriptor along your regular web.xml to describe portlets. This descriptor is called the portlet descriptor and the file is called portlet.xml.

Here is the portlet.xml for our Hello World Portlet.

<portlet-app xmlns=\"http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd\"
xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
schemalocation=\"http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd
http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd\">
<portlet>
<portlet-name>HelloWorldPortlet</portlet-name>
<portlet-class>com.portalzone.example1.HelloWorldPortlet</portlet-class>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
<portlet-mode>edit</portlet-mode>
<portlet-mode>help</portlet-mode>
</supports>
<portlet-info>
<title>Hello World Portlet</title>
</portlet-info>
</portlet>
</portlet-app>


That’s it ! You have written your first portlet application. You can grab the ready to deploy war file from here: example1.war and deploy the application to your container of choice. If you are interested in the source, here it is : example1-src.zip.