Tutorial:

Web development with WebSphere Portal Server & Rational Developer 8.5

TheServerSide.com

Both Cameron McKenzie and Sal Pece have been writing a number of JSR-286 portlet development tutorials for TheServerside. To complement these tutorials, TheServerSide is providing corresponding screencasts that use the code that is documented in these tutorials to demonstrate how Web-based development would be accomplished if an application developer was doing portlet-based Web development with the WebSphere Portal Server as the target runtime and Rational Application Developer 8.5 as the rapid application development tool. 

The following video complements the previously published tutorial on mastering the portlet-based request-response cycle, "JSR-286 development tutorial: Mastering the request-response cycle."

The code itself is by no means overwhelming, as the goal of the portlet development tutorial is to have the learner focus on the key concepts, which in this tutorial is how the incoming request is deciphered using the PortletRequest object, and how a response can be formed and sent back to the user using the PortletResponse object. The tutorial creates at two important portlets, one of which is the CountrySnooperPortlet below:

package com.mcnz.portlet;
import java.io.*;import javax.portlet.*; import java.util.*;
public class GettingHeadersPortlet extends GenericPortlet { 
protected void doView(RenderRequest request, RenderResponse response)                     
                                 throws PortletException, IOException {

   response.setContentType("text/html");   
  PrintWriter out = response.getWriter();     
  out.print("<B>These headers were sent:</B><BR/> ");
    Enumeration<String> e = request.getPropertyNames();        
      while (e.hasMoreElements()){                            
      String name = e.nextElement().toString();             
      String value = request.getProperty(name);            
      out.print("<BR/>");        
      out.print(name + ": " + value);

    }
  }

}

The second portlet developed in this application is the GettingHeadersPortlet. This particular portlet looks at the various header elements sent to the server by the client, and then echoes them back to the user through the portal page on which the portlet resides.

package com.mcnz.portlet;
import java.io.*;
import javax.portlet.*;
import java.util.*;
public class GettingHeadersPortlet extends GenericPortlet { 
protected void doView(RenderRequest request, RenderResponse response)                     
                                    throws PortletException, IOException {

 

   response.setContentType("text/html");   
  PrintWriter out = response.getWriter();     
  out.print("<B>These headers were sent:</B><BR/> ");
 

   Enumeration<String> e = request.getPropertyNames();        
      while (e.hasMoreElements()){                            
      String name = e.nextElement().toString();             
      String value = request.getProperty(name);            
      out.print("<BR/>");        
      out.print(name + ": " + value);

    }

  }

}

The tutorial itself is only about ten minutes in length, so it doesn't require a massive investment of a software developer's time. So if you're interested in learning more about portlet development, these tutorials are definitely the right place to start.

Do you have any quick tips for mastering Portlet API development? Let us know.

Follow Cameron McKenzie on Twitter (@potemcam)

 

 

 

30 May 2013

Related Content

Related Resources