Monday Dec 21, 2009

The Men Who Killed Gandhi

Just finished reading the book "The Men Who killed Gandhi" by Manohar Malgonkar and I was totally delighted to read this brilliant book. Basically if you are interested in Indian history and want to feel the real feeling or the general mood of the country during the 1947-1948 period ( which incidentally was one of the major influential periods of Indian history ), this is one of the best books to take you through that crucial period. The book takes a deep dive into the lives of the people involved in the murder of Mahatma Gandi. These people being Nathuram Vinayak Godse, Narayan Apte, Vishnu Karkare, Madanlal Pahwa, Badge and Shankar Kishtayyia. It goes deep into the personal lives of these folks, how they lived, and their personalities, what went on in their heads during the 1948 times, the effect of partition, release of the 55 crores to Pakistan, how they planned the murder of Mahatma Gandhi. It goes deep into the initial plan to kill Mahatma Gandhi on 20 Jan 1948 and how that failed. And even though sufficient clues were there for the police to pickup and their awareness of a plan to kill Gandhiji by the 24th of Jan 1948 and even then the folks succeeded in killing Gandhiji.

The book is extremely honest, unbiased and feels like a thriller novel. The best thing i found about the book is that it gives the facts and tries to present a true picture of pulse of the country at that time, and it does so without taking sides.

This is a MUST read for all who are interested to know the facts behind why Gandhiji got murdered. And even today, why the close relatives and friends of Nathuram Godse and the others involved in this gruesome act, still regard the murderers as 'martyrs' who gave away their lives for a 'noble' cause.

 The book contains some very exclusive unpublished photographs. Going to buy this book as I feel it is a treasure.

Monday Nov 03, 2008

Be Social by running SocialSite on Tomcat

Sometime ago, I saw an announcement of the first release of SocialSite. Basically it is a Java implementation to add social features to your existing website. Check out Arun Gupta's blog on the usage of SocialSite. I thought of trying it out and it works fine on Glassfish. Out of the box there was no way of getting it to work on another container, such as Tomcat. Not very social I thought :-)

Anyway thought of trying to get it to run on Tomcat. Following is the procedure to get SocialSite to work on Tomcat. If you understand and follow what is going on, and why each of these steps is being done, it should be trivial to port SocialSite to run on any other container.

These instructions are for Tomcat 5.5 and MySQL. I would rather you proceed with the source code download of SocialSite and build the distribution from there. You can download the distribution from the SocialSite site, and add the following things mentioned in your downloaded bundle, but I haven't tested that. But I don't see a reason why that shouldn't work either.

So go ahead, download the source code for the SocialSite as per instructions given here. Once you have the source code downloaded, follow the steps given below to get SocialSite to work on Tomcat.

SOCIALSITE_SRC_HOME is where you downloaded the source code for SocialSite.

Configure the Global JNDI Resource for the database.

SocialSite uses a JNDI resource by the name of 'jdbc/SocialSite_DB' to access your database. So you need to create a JNDI resource by that name. You can refer to the Tomcat 5.5 documentation page here to get information on how to define a per-application JNDI resource using the <Resource> tag in your context.xml. Or you can read along as I show below how to do it.

Under the SOCIALSITE_SRC_HOME/web/META-INF there is a file called context.xml. Make sure it looks following and save the file. Ofcourse make sure that entries for url, username and password do match for your MySQL database, so that the connection to the DB succeeds. The other JNDI resource is about javax.mail.Session that SocialSite uses to send out e-mails.

<Context path="/socialsite">

<Resource name="jdbc/SocialSite_DB" auth="Container"
type="javax.sql.DataSource" user="root" username="root" password="abc123"
driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/socialsite"
maxActive="100" maxIdle="30" maxWait="10000"/>

   <Resource name="mail/SocialSite/Session" auth="Container"
description="Mail Session for SocialSite" scope="Shareable" />


Update persistance related entries of SocialSite so Tomcat loves them

The default SocialSite install works on Glassfish. Glassfish is a container which supports the JavaEE 5 specification and hence has a persistence engine built-in. SocialSite uses the JPA features to interface to a database. So to get SocialSite to work with Tomcat we need to enable persistence capabilities in it. Fortunately SocialSite bundles the EclipseLink libraries which include a persistence provider.

However, the persistence.xml included in the SocialSite includes a persistence.xml which tries to lookup the DB via a JNDI lookup. This doesn't work outside a EJB container by default, and Tomcat is not a EJB container. So to enable EclipseLink to pick up the DB details we need to configure it as we would be doing in a pure Java SE environment. For doing this you will have to modify the SOCIALSITE_SRC_HOME/src/java/META-INF/persistence.xml accordingly. The entries which you have to modify are indicated in red. Make sure the entries for the DB marked in red are correct for your DB install.


 Copyright 2007-2008 Sun Microsystems, Inc. All rights reserved.

 The contents of this file are subject to the terms of either the GNU
General Public License Version 2 only ("GPL") or the Common Development
and Distribution License("CDDL") (collectively, the "License"). You
may not use this file except in compliance with the License. You can obtain
a copy of the License at
or legal/LICENSE.txt. See the License for the specific language governing
permissions and limitations under the License.

 When distributing the software, include this License Header Notice in each
file and include the License file at legal/LICENSE.txt. Sun designates this
particular file as subject to the "Classpath" exception as provided by Sun
in the GPL Version 2 section of the License file that accompanied this code.
If applicable, add the following below the License Header, with the fields
enclosed by brackets [] replaced by your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"


 If you wish your version of this file to be governed by only the CDDL or
only the GPL Version 2, indicate your decision by adding "[Contributor]
elects to include this software in this distribution under the [CDDL or GPL
Version 2] license." If you don't indicate a single choice of license, a
recipient has the option to distribute your version of this file under
either the CDDL, the GPL Version 2 or to extend the choice of license to
its licensees as provided above. However, if you add GPL Version 2 code
and therefore, elected the GPL Version 2 license, then the option applies
only if the new code is made subject to such option by the copyright

<persistence xmlns="" version="1.0">

 <persistence-unit name="SocialSite_PU" transaction-type="RESOURCE_LOCAL">
<!-- <provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider> -->
<!-- <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> -->
<!-- <provider>org.hibernate.ejb.HibernatePersistence</provider> -->


<property name="eclipselink.jdbc.platform" value="oracle.toplink.platform.database.mysql"/>
<property name="eclipselink.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="eclipselink.jdbc.url" value="jdbc:mysql://localhost:3306/socialsite"/>
<property name="eclipselink.jdbc.user" value="root"/>
<property name="eclipselink.jdbc.password" value="abc123"/>

<persistence-unit name="SocialSite_PU_Standalone" transaction-type="RESOURCE_LOCAL">
<!-- <provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider> -->
<!-- <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> -->
<!-- <provider>org.hibernate.ejb.HibernatePersistence</provider> -->


Build the SocialSite distribution


ant dist

The above will build a folder called SOCIALSITE_SRC_HOME/dist under which the SocialSite distribution is created. In the distSocialSite/webapp folder is the socialsite.war file. Make sure the two steps you did above do end up showing properly in the built war file.

Create tables in database of your choice

Under the SOCIALSITE_SRC_HOME/dist/SocialSite/dbscripts directory there are directories, one for each database supported. Choose MySQL ( since I did the setup with MySQL ). Login to MySQLAdmin, and create a database of name 'socialsite'. The DB name can be anything of your choice. Make note of this name, as this is the name of the DB we will be using in all JDBC URL's which get configured in different steps in this blog. Now go ahead and execute the createdb.sql script in the context of the 'socialsite' database.

Create the Realm for SocialSite

Socialsite by default authenticates users to a realm named "SocialSite_UserRealm". So you must create this realm in Tomcat. You can refer to docs for information on how to create a realm. Or if you are impatient here is how you do it. Open the file TOMCAT_HOME/conf/server.xml and add the following line to it. There are several entries in this file for JDBCRealm, but they are commented by default. Uncomment the one for MySQL, and make sure your entry matches the one below. Ofcourse, change parameters to match your database configuration.

<Realm  className="org.apache.catalina.realm.JDBCRealm"
connectionName="root" connectionPassword="abc123"
userTable="userapi_user" userNameCol="username" userCredCol="passphrase"
userRoleTable="userapi_userrole_view" roleNameCol="rolename"
resourceName="SocialSite_UserRealm" digest="SHA"/>

Enable SSO Valve

Enable the SSO valve in TOMCAT_HOME/conf/server.xml. It is already there and probably commented out.

   <Valve className="org.apache.catalina.authenticator.SingleSignOn" />

Prepare Tomcat for being SocialSite enabled by making JARS available to apps.

Glassfish is a JavaEE compliant App server and hence has the full webservices stack bundled with it. For Tomcat you need to enable this stack, since SocialSite uses some parts of it. For that purpose,

  1. Download the JAX-WS RI from hte JAX-WS site. Copy all jars (except sjsxp.jar) from the JAX-WS-INSTALL/lib folder to the TOMCAT_HOME/shared/lib folder.

  2. Copy sjsxp.jar to the TOMCAT_HOME/common/endorsed directory.

  3. Also download the stax.jar from here and copy that jar also the TOMCAT_HOME/common/endorsed directory.

  4. Copy mail.jar and MySQL JDBC Driver (mysql-connector-java-3.1.12-bin.jar) to TOMCAT_HOME/common/lib folder.

Enable JSTL in Tomcat

Tomcat 5.5 doesn't have JSTL support by default. From the Jakarta JSTL site, they seem to suggest to use the Glassfish JSTL implementation. So following that, we pick up the appserv-jstl.jar from the GLASSFISH_HOME/lib to TOMCAT_HOME/common/lib folder.

Enable SSL on tomcat, or disable SSL login in SocialSite

Follow this page on Tomcat docsIf you enable SSL on Tomcat on port 8443.

SocialSite Admin Site

To enable SocialSite administration, under the SOCIALSITE_SRC_HOME/dist/SocialSite/bin folder there is a setup-glassfish.xml file. In this there is a create-admin-user target. Run that target as follows:

ant -f setup-glassfish.xml create-admin-user

to create an admin user for your socialsite installation. You might have to fill in properties in the sjsas.props file to get it to work fine.

Wednesday Jan 02, 2008

Charting Portlet using JSR-286

A while ago I had written an SDN article on how to generate charts dynamically in portlets. Following up on that, I have created a portlet that uses the JSR-286 feature of serve resources, to dynamically generate charts by reading its data from a JDBC compliant database. The essential feature of this portlet is that the image is generated dynamically and served via a serve resource call and isn't stored in any temporary location. The portlet can be run under any portlet container that supports JSR-286 specification. It has been tested on OpenPortal Portlet Container which supports the draft 19 of the JSR_286 specification. You can download the portlet war file from here.


Tuesday Oct 16, 2007

JSR-286 compliant ajax enabled Atom and RSS news reader Portlet

A colleague of mine, Satya a few days ago talked about JSR-286 and resource serving. He was describing what it is, and how it is a part of the JSR-286 spec. Satya incidentally was one of the key folks in implementing the same for the Open Source Portlet Container. He pointed me also to a nice article by Deepak Gothe and himself about the new JSR-286 specific features in the portlet container.

 After going through the article I was waiting to get started with the JSR-286 implementation of the portlet container and resource serving in particular. So I have implemented a "RSS and Atom feed reader" portlet using the Open Source Portlet Container. The portlet is AJAX enabled as well. To see a small screencast of it in action click here.

This is how it looks (click to enlarge and see in a new window):

 If you want to use this portlet, or try it out, you will need a portlet container which supports the JSR-286 spec, and resource serving in special. As mentioned earlier the Open Source Portlet Container is one of the best. You can get it from the web site as mentioned in the link, or get is as part of the JavaEE Tools Bundle (Choose to "Download with Tools"). If there is interest in this portlet, let me know and I can make it available.

 Read where you can get this portlet source code from on my personal blog@blogspot.

Monday Oct 08, 2007

Presence - Dial tone of this century ...

How many times you have wanted to make an important business or a personal call, and picked up the phone to call the other party, but the call ended unsuccessfully, since all you managed to reach was the other party's voice mail? Such unsuccessful calls can be a serious drag on productivity and not to mention the frustration it causes, since instead of talking to each other the parties get to talk to the infamous 'voice mail'.

Or maybe the person you thought was in office actually was on the customer site today and was not reachable on his office number you just dialed. Well this brings in the concept of 'presence' which is so prevalent in the IM world. You begin to chat with a party only when his icon in the chat indicates that he is 'present'.

Now wouldn't that be really nice if we can apply this concept to telephone dialing as well. And why just telephones, we should be able to extend the concept of presence far beyond that.

A user, may opt for several ways in which he can be reached, phone, IM, SMS, Email etc. All of these are different modes of reaching the person. Now, imagine that this same person, can specify or update a unique "address" or a "URI" for each of the means to reach him. Then under his buddy icon, in a client application ( a universal communicator client), on right clicking his name, there appear several of these options to interact with him.

Clicking on the URI corresponding to a phone, will place a IP telephony based call, clicking the URI for email, could launch an application capable of sending an email. As long as the person has kept his information updated on the "Presence" server, the other parties are always able to get in touch with the person, based on his preferences of course.

Thus it would be appropriate to call "Presence" as the dial tone of this century. SIP ( Session Initiation Protocol ) seems to be right way to achieve this kind of communications.

From the portal perspective, the concept of "Presence" makes an absolute sense, since portal is a great way of achieving collaboration and bringing people together. Using a SIP server and a proxy, it seems that getting this above mentioned concept of "presence" into a portal has great potential value. Watch this space for more information on this topic.

Tuesday Aug 07, 2007

Flex or Ajax .. well both!

The release of Flash Player 9 included a new External API using a class file called the ExternalInterface that allows for the communication between JavaScript and Flash applications. To create the communication link and pass data between JavaScript and Flex, the developer had to create custom code to handle each call.

The newly introduced Flex-Ajax Bridge has simplified the usage of this API. By simply including the necessary classes, the bridge exposes all of the classes within the Flex application to JavaScript. You can almost create anything in your Flex application using JavaScript instead of ActionScript.

So if you are a JavaScript pro and want to try out Flex this is a good time to do so!

Friday Aug 03, 2007

Update: Flex up your portlets

A while ago I had talked about Rich Internet Applications on my blog and talked in detail about Flex. You can read that entry here. I had promised to put a tutorial/entry on how to create a portlet out of your Flex application, but I
didn't get time to post the entry.

Recently, I helped my colleague Murali on getting his Flex app converted to a portlet and he has been prompt enough to post the instructions on his blog here. Thanks Murali.

Wednesday Aug 01, 2007

A Solution: Maths Fun Again.. Again

So the solution to my previous entry and the one prior to that was provided by a few folks as (root 2), which is actually quite trivial in my opinion. The actual question that has been bothering me was what i posted in the comments to whatever  few replies i got:

That is , what actually is . If the answer to both questions (blog entries) is , then how come is 2 as per my first blog entry and equal to 4 as per the second entry. This is the one I was actually looking for an answer to. I have kind of an idea what it could be, I will put my explanation here, and hopefully it makes some sense.

is actually limit of the sequence ,, ...

It is trivial to prove that the above sequence is increasing and is upper bounded by 2.

Coming back to the original question (the previous two blog entries marked above) which can be rewritten as .

 I tried to plot the graph of this function and it comes out as follows:


This proves that given a value of x, there are two values for y. And for x = , we know these values are 2 and 4. But we just indicated above that the sequence is upper bounded by 2. So the value 4 can't be possible for .


Hope it makes some sense.

Friday Jul 27, 2007

Maths Fun Again .. Again

Some of the folks answered this in the comments to my previous entry as the answer to x being equal to . However if that is true then what is the value of x in the following equation?


Getting interesting now I guess :-)

Monday Jul 23, 2007

How about a Semantic Community Portal?

Community can be defined as a group of users having common interests. As organizations become highly dynamic and the people that join them become more geographically dispersed, the need for improved ways to share and distribute data and information amongst the community or organization members has increased dramatically.

Speaking in terms of the Semantic Web, these community members share similar ontology items since in most probability their cultural backgrounds, work activities etc might be similar. "Semantic community portals" can make use of Semantic Web technology and shared community terms to create connections between people and people, and also between people and the information that they produce.

So how exactly would you define semantic community portal?

Orkut and LinkedIn are examples of community web portals where the people and their relationships were clearly defined using online social networking. However there is a strong connection between these social networking services and semantic community portals. For example consider Orkut or Linkedn using the FOAF ( Friend of a Friend ) ontology to describe its members profile and their relationships. This will bring these now separate social networking sites to inter operate with each other. This will help in bringing the people together in a 'universal social network'. For this to become a reality more and more of these social networking sites need to start using the FOAF and other related ontologies, in an attempt to make the data within them distributed and decentralized.

The onltologies that are typically most commonly used by the community web portals are the ones used to define people (vCard, FOAF) and documents ( RSS). However staying within these ontologies is far too limited for the currently evolving semantic web.

SIOC is an initiative that seems to be a step in the right direction from the semantic community portal perspective. Basically the SIOC tries to capture as much information as possible about the community web sites and the information that is contained within them. Have a look at the two figures below taken directly from the SIOC web site which clearly demonstrate the future of the semantic community portal.

SIOC Model

SIOC Integration with Legacy Apps and Today's Apps
SIOC has the ability to link all sorts of entries like Blogs, Forums, Mailing Lists from and amongst various community sites. Using SIOC we will have the ability to make the information contained within links in HTML documents, discussions in forums, trackbacks, replies, followups etc available explicitly for machine-processing. (That is the goal of the semantic web )

However, a full-fledged framework for community-driven ontology management should go beyond simple tagging and should enable merging of community portals with established practices for ontology management. The objective of community-driven ontology management is to provide means for a large number of users to build and adopt the Semantic Web, via practices for ontology management all in the community space. Such a portal will allow end users to define the structure of the content (i.e., develop ontologies), populate ontologies and define the ways in which this content is managed on Semantic Web community portals.

Reference: Berners-Lee, T., Hendler, J., & Lassila, O. (2001). The Semantic Web : Scientific American

Friday Jul 20, 2007

Maths Fun Again

Given that : 

What is the value of x?

Locker Mania - Answer

Although there were solutions to this provided by Murali and Eric in the comments section and they are correct. Just posting it here for more general viewing. BTW, I went through the C program written by Eric, it was really nicely written program with neat output as well. Really nice!

 Anyway back to the answer.

The state of any locker N will remain unchanged from the beginining as long as N = P \* Q, and P and Q happen to be distinct (There can be multiple combinations of P and Q). That means, given the 10th locker, its state will be toggled by the 1st and the 10th member. Its state will again be toggled  by the 2nd member and then again by the 5th member, thus its state remaining unchanged. This is since the factors of 10 are (1,10) and (2,5)

 For locker number N where N =P\*Q, and P and Q are same, i.e locker numbers which are perfect squares, there will only be one state change and hence are the ones which will remain open in the end.

Example, locker number 9. Its state will be changed by (1,9) member and again by the (3,3). But since the 3rd member can only toggle once, we can see that the state if the 9th locker will be open ultimately. Same for all perfect squared numbered locker till 100.


Tuesday Jul 17, 2007

Locker Mania

There is a locker room in the club and they are numbered from 1 to 100. There are 100 members of the club who will enter the locker room in the following sequence. When the first member enters, he opens all the lockers. When the second member enters the locker room, he closes all even numbered lockers. When the next member enters the room, he toggles the state of every locker which is a multiple of 3.

 This process continues till all the 100 members have been through the locker room. At the end of this process, which are the lockers that are open?

Wednesday Jul 11, 2007

Secure Remote Access (SRA) in 7.1

Sun Java Systems Enterprise Secure Remote Access version 7.x

The 7.0 release of Portal Server saw the introduction of the JMX Administration. All administrative interfaces in portal now used mbeans to manage the various servers and configuration. A single command line interface was provided for all the administrative activities ( viz. psadmin). The Portal Admin Server (PAS) is the admin server that holds all the configuration of the various mbeans known to the JMX Server. The PAS held its configuration/bootstrap information in LDAP.

Gateway, the main workhorse of Secure Remote Access (SRA) component of Sun's JES stack, resides in the DMZ ( De Militrized Zone) and hence doesnt or rather shouldn't have direct access to LDAP which is inside the corporate firewall. So as a workaround in 7.0 there was a requirement of installation of a local directory server on the Gateway host. This directory server was not required by the Gateway process per se, but was required to bootstrap the administrative interface of Portal Server (PAS). This local directory server contained only the bootstrap information to startup PAS and nothing else. Once the GW is started up using psadmin, this local directory server on the gateway node could very well be shut off and that wouldn't affect the gateway at all. This (installation of a local directory) however was a major restriction and was a big no no.

So in 7.1, release this restriction was done away with. The PAS module on the local gateway box uses a file based JNDI mechanism to load its configuration information and hence no need for a local LDAP on the gateway box. So far so good.

However it recently came to my attention that there was a bug in which it was reported that the LDAP port between GW and the Portal Server was required to be opened. I have traced the issue down and have done the fix for that. It should be checked in by EOD tomorrow. Once this fix is done in the code
base and the product patched with the fix, the flow of traffic from an administrative perspective should follow exactly the diagram below.

So in 7.1 the scenario, as far as the GW, Portal nodes and the firewall is concerned looks pretty much like this. Note this figure is only for as far as the administration of GW is concerned. What I mean by that is, executing of any SRA related psadmin commands on the gateway node. Once the step 8 is completed in the figure below, the gateway starts up and starts serving pages from the portal ( ofcourse the HTTP/HTTPS port for the portal server needs to be opened in the firewall as well, but like I mentioned the figure essentially talks about the admin interface only.)

Tuesday Jul 03, 2007

New Version of Eclipse Portal Pack with Action Support

I have uploaded the source code for the new version of Eclipse-Portalpack. I have been playing with the idea of making portlet development easy... and not just for rendering the view mode or the edit mode of the portlet but also in processing actions easily from the portlets. To this extent this is my first attempt in making this happen. Check it out and let me know if you find it useful and suggest any enhancements requests if any. I will be enhancing this further myself ( as there are areas I think that need it, but do let me know your suggestions )

Okay back to the new version. The new version supports the following new things :

    - It is now built on the latest version of JAXB .i.e version 2.1.
    - It has a new feature of adding a new portlet action very easily to your portlet, and to implement the action you just need to implement one method "execute()" in your action class and almost no code change to your portlet class is needed. You just specify what page to go to once the action is processed and the portlet has the code to automatically send you to the new page once the action is executed sucessfully. In case of an error that happens in your action's "execute()" method, the portlet will redirect you to the error page that gets created automatically for you when the portlet project was initially created.

Enhancements to this :

There are a couple of enhancements that I am still working on. If you think you can contribute to any of these please join in and contribute.

   - There are enhancements to the GUI for action creation needs some work. 

Suppose I want to develop a simple portlet which shows a form to collect some inputs from the user. The form might ask the user for his first name, last name and the email address. When the user submits this form, the data is collected at the server, and persisted to a data store. Once the data is persisted the user is shown a thank you page. Now assume the above needs to be done in a portlet. The scenario described above can be done using a portlet as shown below in the picture:

When developing this portlet the developer needs to write code in his processAction() method to do the following :

  • Recognise the type of action this request is. In our case there is only one action so this case is simple.

  • Collect the data from the form and populate a bean with that data.

  • Put the bean in session data to be accessed in doView() mode.

  • Now when the portlet container calls the doView() method, access the bean stored in session in previous step and do the actual action

  • Dispatch the request to the destination JSP page.

All the above needs to be done by the developer whenever he writes a particular action. ( This is one way of doing this )

I wanted to make this a little easier to do, so I have added new code to the Eclipse Portal Pack project to make this easier. This is a very early version of it, so please bear with it, as I make further improvements. But feel free to try it out and give suggestions, or better still join on the project and contribute.

Developing the above portlet with the Eclipse Portal Pack Project

A screencast of creating a simple portlet project and a sample portlet is shown here.

Now that we have a sample portlet ready. Let's go about adding this new action that we wanted. Let's first create the JSP page that will show the form to the user in the view mode. By default the project would have created a JSP for the view mode called view.jsp in your /WEB-INF/jsps/ folder. Open this JSP file and add the following code to it.

<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="UTF-8"%>
<%@page import="javax.portlet.\*" %>
<%@ taglib uri="" prefix="portlet" %>

<portlet:actionURL var="portletUrl" />

<form id="form1" name="form1" method="post" action="<%=portletUrl.toString()%>">
First Name : <input type="text" name="fname" type="text"><br/>
Last Name : <input type="text" name="lname" type="text"><br/>
Email : <input type="text" name="email" type="text"><br/>
<input type="submit" name="Submit">

The lines in bold indicate the form that will be displayed to the user in the view mode. It presents the user with fields to accept his first name, last name and email address and then there is the submit button which submits the form to the portlet via the portlet:actionURL variable defined above.

Now this is where the new Eclipse Plugin can help you in making your life easier. Let's call the action to collect the user data and put it to datastore as "CollectData". Right click on the portlet project in Eclipse, and down at the bottom you will see a menu entry called "Portlets->Create new Portlet Action" as shown below in the picture.

So here is what we want to do, we want to define a new action called CollectData, which we want implemented by a class of our choice, in this case lets say com.sun.portal.test.actions.CollectDataAction, and when our action is complete we want the portlet to take us to the page defined in /WEB-INF/jsps/done.jsp. So fill up the dialog box as shown below and click Ok. ( Like I said this is the first version so I haven't added any error checking as of yet, it will be coming pretty soon though ).

On clicking Ok, you will see a new action class called CollectDataAction created under the package com.sun.portal.test.actions. Open this class in Eclipse and it will appear as below:

package com.sun.portal.test.actions;

import javax.portlet.ActionRequest;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import com.sun.portlet.core.actions.ActionExecuteException;
import com.sun.portlet.core.actions.BaseActionFormBean;

public class CollectDataAction extends BaseActionFormBean {

 public CollectDataAction(ActionRequest request) {

public boolean execute(RenderRequest portletRequest,
RenderResponse portletResponse) throws ActionExecuteException {
// Put your logic of executing the action for this request here.
return true;

So as you can see, all you need to do is implement the method "execute()" in your class. In the execute() method, you can access the form parameters that your view.jsp sent in as getParameter(String), getParameterNames() and getParameterValues(String) as usual.

Also to invoke this action the only other thing you will need to do is, add a hidden field in your view.jsp form called ACTION_NAME, and its value must exactly be the action you want executed when the form is submitted, which in our case is "CollectData". So our view.jsp page in completion will look as below :

<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="UTF-8"%>
<%@page import="javax.portlet.\*" %>
<%@ taglib uri="" prefix="portlet" %>

<portlet:actionURL var="portletUrl" />

<form id="form1" name="form1" method="post" action="<%=portletUrl.toString()%>">
First Name : <input type="text" name="fname" type="text"><br/>
Last Name : <input type="text" name="lname" type="text"><br/>
Email : <input type="text" name="email" type="text"><br/>
<input type="hidden" name="ACTION_NAME" value="CollectData">
<input type="submit" name="Submit">

The only changed line is shown in Bold and Italic.

That's all that is needed to implement this action from your side. Ofcourse, you need to write the done.jsp file to which the portlet will dispatch the view after the action is executed.

To summarise, to implement any new action, all you need to do in addition to writing the source JSP and the target JSP is :

  • A hidden variable called ACTION_NAME in the source JSP page form.

  • Implement the execute() method in your Action Bean.

Rest of the stuff is handled for you!!

Let me know if you like it, by posting your comments.




« July 2016