This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Portals and Portlets and the fly likes Basics Help need for Portlet development Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Portals and Portlets
Bookmark "Basics Help need for Portlet development" Watch "Basics Help need for Portlet development" New topic
Author

Basics Help need for Portlet development

William Moore
Greenhorn

Joined: Jan 27, 2006
Posts: 5
Hi,

I am totally new to the world of Portlets, I don't even know how to start though i have set up a workspace and am currently running the HelloWorldPortlet in WSAD 5.1.2 but i need some very basic help on how to code a Portlet using JSR168.

Thanks in advance,
Bill
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

check out this thread. It lists a few tutorials available through IBM's portal website.

Good luck!
Nit Sharma
Greenhorn

Joined: Jan 27, 2006
Posts: 9
Hi,
I would recommend using infocenter for learning.

http://www-128.ibm.com/developerworks/websphere/zones/portal/proddoc.html#500


Regards<br />Nitin<br /> <br />Sun Certified Java programmer <br />Sun Certified Web Component Developer(SCWCD)<br />Sun Certified Enterprise Architect(SCEA)<br />IBM Certified Solution Developer WebSphere Portal V5.1
William Moore
Greenhorn

Joined: Jan 27, 2006
Posts: 5
As in the case of a JSP, a servlet runs in the background and provides the functionality for the page, is that the same with a Portlet. You got to have a Portlet running in the background which provides the same functionality to a JSP?
Rohit Lal
Greenhorn

Joined: Sep 25, 2003
Posts: 20
Bill:

Even I have just entered the world of protlets a month back. I'm using the JSR-168 api too. Here's how I would go about explaining portlets:

A portlet application is a web application in itself. A portlet also dishes up web content and in fact uses an api very similar to that of the Servlet api. But it does not inherit/implement anything from the servlet api, mind you. E.g. you have PortletRequest, PortletResponse, PortletRequestDispatcher. etc. etc. doing similar functions as in the servlet api, but they do not inherit from the servlet api. However, there is a major difference between servlets and portlets which I'm going to try to explain below-

A portlet dishes up web content that forms PART not whole of a browser page. A web portal will typically be composed of many portlets, each taking up space on the page. Now comes the interesting part - in a servlet the action and rendering tasks are performing in one go through the service method. i.e. you would call the business validators and do any other tasks before calling the relevant JSP page all through the service() method. this is because the content served by the servlet forms the entire page. so the servlet just processes all the tasks and then serves the content through one service() method.

But, in a portlet, since it renders only part of the browser page, it cannot do this processing and rendering all at one go. This is because, in the case of a portal having say 2 portlets, portlet A and portlet B, a user may perform some action on portlet B resulting in iot needing to be refreshed. But since the entire page will be refreshed, portlet A will also be rendered again. No action was performed on portlet A, yet it was refreshed again. in the case of portlet B, the action was performed on it and then it was rendered again automaticlly. the action on the portlet happens thru the processAction(...) method and the rendering takes place thru the render(...) method. the action changes the state of the portlet, while rendering shows the current state of the portlet.

It is the job of the portlet container to tranlate HTTP into portlet api and vice-versa. So portlets live inside a portlet container and dish out content which is passed on to the portlet container which then translates into HTTP and browser readable format.

Also - just as we have doGet(), doPost() called from the service() method, same way we have in Portlets the doView() and other methods called from the render(...) method

here's a very simple example of a portlet:
HelloPortlet.java
=====================
package hello;

import java.io.*;

import javax.portlet.*;

/**
*
* A sample portlet based on GenericPortlet
*
*/
public class HelloPortlet extends GenericPortlet {

/**
* @see javax.portlet.GenericPortlet#doView(RenderRequest, RenderResponse)
*/
protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
response.setContentType(request.getResponseContentType());
response.getWriter().println("Hello World");
}

/**
* Process an action request.
*
* @see javax.portlet.Portlet#processAction(ActionRequest, ActionResponse)
*/
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, java.io.IOException {
// Add action request handler here
}
}
============================


web.xml
========
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app id="WebApp_ID">
<display-name>Hello</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<taglib id="PortletTLD">
<taglib-uri>http://java.sun.com/portlet</taglib-uri>
<taglib-location>/WEB-INF/tld/std-portlet.tld</taglib-location>
</taglib>
</web-app>
===================================



portlet.xml
===========
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd" id="hello.HelloPortlet.dbff84bf80">
<portlet>
<description>This is the Hello World portlet</description>
<description xml:lang="en">This is the Hello World portlet</description>
<portlet-name>Hello</portlet-name>
<display-name>Hello portlet</display-name>
<display-name xml:lang="en">Hello portlet</display-name>
<portlet-class>hello.HelloPortlet</portlet-class>
<init-param>
<name>wps.markup</name>
<value>html</value>
</init-param>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
<portlet-info>
<title>Hello portlet</title>
</portlet-info>
</portlet>
</portlet-app>

=======END==================



Originally posted by William Moore:
Hi,

I am totally new to the world of Portlets, I don't even know how to start though i have set up a workspace and am currently running the HelloWorldPortlet in WSAD 5.1.2 but i need some very basic help on how to code a Portlet using JSR168.

Thanks in advance,
Bill


Rohit Lal<br />SCPJ2 (2000)
William Moore
Greenhorn

Joined: Jan 27, 2006
Posts: 5
Hi Rohit,

Do you have any idea about interportlet communication, any quick help would be be appreciated.

regards
Rohit Lal
Greenhorn

Joined: Sep 25, 2003
Posts: 20
Sorry Bill,

No idea yet on inter-portlet commmunication. Not delved into that yet. I think there are some examples on the IBM site. A search on Google might throw up the related links.

Rohit
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Basics Help need for Portlet development
 
Similar Threads
weblogic portlet
Nested Portlets
share (user/preference) data between portlets (ipc with jsr 286 ?)
HOw to get session variables between portlets ?
Calling one portlet from another portlet