Wednesday 30 September 2009

How to create a JSR 168 Struts Portlet

Recently I had published an article on creating a JSR 286 compliant Portlet. Here is the URL for that Blog Post.

Struts Portlet creation tutorial from scratch using Eclipse and deploying the same to a Portal server like Liferay:

Creating a Struts Portlet from Scratch may not be that easy if you are doing it for the first time.

When I started to create a sample hello world Portlet using eclipse I never thought it will take me good amount of time to figure out the exact steps.

That is the primary reason for me getting down to help those struggling with a Struts Portlet.

Following are the steps for doing this:

1. In our earlier tutorial we had explained the steps needed to create a basic JSR 168 Portlet. You need to do that first. Create a simple portlet in eclipse.
2. Next you need to understand the structure of a struts application. The basic file which defines a Struts application is struts-config file. This has the mapping defined for various actions. The controller processes the request based on the mapping defined here.
So we need an entry in struts config for every struts portlet we create. To understand the basic tags of a Struts Config file and how the mappings are done visit this blog Post
3. Next part is to create an action class, a jsp and a mapping in the struts config file.
Create a new action class, say HelloWorldAction in a package structure like com.helloworld.src
4. Create a jsp like HelloWorld.jsp within webcontent
5. When you deploy your Portlet then the request goes to portlet.xml file, where it looks for the Portlets. Suppose you want to see this Hello World Portlet in Liferay or any Portal Server. You add the Portlet and that is when portlet.xml comes into action.
From portlet.xml it looks for the mapping and goes to struts config file. After which appropriate action class is called and then jsp leading to execution of render method.

Here is a Sample RAR created by me which will guide you. Import the RAR in your IDE and thengo through package structure. Especially through portlet.xml and struts.xml. Also copy all the jars in your web-inf lib folder.

This should help you get started. I will provide some more details on this in my next Post.

3 comments:

  1. Hello, can you help me create a JSR168 struts portlet using Netbeans and Liferay portal?

    ReplyDelete
  2. Can you upload the RAR again?

    ReplyDelete
  3. Hi Dorian, I will try to find the RAR and upload it again. Meanwhile try to follow the steps and let me know if you face any problems..

    ReplyDelete