Thursday 5 December 2013

Implementing email functionality in a JSR portlet using Liferay API's

Many a times we have a requirement to implement email functionality in our Portlets.
A simple use case can be the contact us form on your website. When the user submits it, it should send an email to the concerned department.

I am going to explain how to implement this.

I am using Liferay Portal and a JSR compliant portlet. We will be using Liferay's SubscriptionSender class to do the job of sending emails.

Another important thing is we can either use the tmpl file(email template) to do this or use a web content to
create the email template.

The advantage with web content is that it can be localized, which is currently not possible with a tmpl file, at the time of writing this post.

Here are the steps

1. If using a tmpl file create one like email_body.tmpl

The content of  this file can be something like

Tuesday 8 October 2013

How to include external CSS or JavaScript file to the JSP in your Portlet

If you have an external JS or CSS file and want to include that in your JSP, here is a simple way to do that.

<script language="javascript" src='<%=renderRequest.getContextPath() + "/js/sample.js" %>'>
</script>


<link rel="stylesheet" type="text/css" href="<%=renderRequest.getContextPath() + "/css/sample.css" %>">

The CSS file is located at /webapps/css/

The JS file is located at /webapps/js/

And JSP is located at /webapps/WEB-INF/jsp

Hope this helps.

Friday 31 May 2013

Applying Listeners to JSR Compliant Portlets

As per the JSR 286 Specification the following Listeners, which work with Servlet Requests, can be applied to requests targeted towards Portlets.
  • ServletContextListener 
  • ServletContextAttributeListener
  • HttpSessionActivationListener
  • HttpSessionAttributeListener
  • HttpSessionBindingListener
  • ServletRequestListener.

For this to work the Container needs to set a variable javax.portlet.lifecycle_phase.

Lets see an example.

Wednesday 22 May 2013

Using Jenkin's to perform Build and Deploy for our custom Portlet : Setup Continuous Integration

In the last article we saw the steps to create a new JSR 286 Portlet from Scratch.

Now every time we make some change we need to build our project and then deploy it.
How cool it will be if these steps can be taken care of by click of a button.
Automation of such tasks can not just save time but also make us more efficient.

Below is a set of steps which can be used to setup Jenkins and then build Project using that. Its really simple. Jenkins is a Continuous Integration tool for automation of build, test and deploy.

Thursday 16 May 2013

Create a simple JSR 286 Portlet - Part 2

In the last article we had completed the setup.


Now we will create our first JSR 286 Portlet.

1. In Eclipse navigate and go to File->new->other.





Create a simple JSR 286 Portlet using Maven, Eclipse IDE, MySql - Part 1

The Portlet we are going to create can be run on any Portal Server. I have used Liferay Community Edition since its available for free.

The tools we are going to use are:

1. Java V 1.5 and above.
2. Maven: It makes life so much easier.
3. Eclipse IDE
4. MySQL database
5. Liferay Community Edition bundled with Tomcat: Latest version is available at liferay.com

Monday 6 May 2013

Comparing Servlets and Portlets Part 3 : Portlet deployment descriptor file


In the last article we saw how a RequestDispatcher works for both Servlets and Portlets.

Difference between a web and a portlet application.

A basic web application will have a web.xml file, Servlet classes and JSP's. The web.xml file helps to configure the Servlets which make the application. It helps a developer to define which URL's will be handled by which Servlets. How security will be applied to these URL's, session management etc.

Comparing Servlets and Portlets Part 2 : Using RequestDispatcher


In the last article we saw how we create a simple Servlet or a Portlet by implementing or extending appropriate interfaces and classes.

Lets continue to see what other differences are there.

RequestDispatcher

Unlike a Servlet where we can use either ServletRequest or ServletContext to get a RequestDispatcher object in a Portlet we can only use the PortletContext to do that. Just to refresh your memory RequestDispatcher can be used to forward the request to another Servlet or a JSP for further processing.

Friday 3 May 2013

Comparing Servlets and Portlets Part 1 : Understanding the similarities and differences


People familiar with Servlet technology will be able to relate to Portlets. The concepts are more or less the same for both the technologies.

Lets do a quick walkthrough:

To start with the lets talk about their containers.

A container provides the environment in which the application can run. For running a servlet we will need a web application container like Tomcat.
On similar lines for a Portlet we need a Portlet Container. Most of the Portals today come with an inbuilt Portlet container to serve requests.

Thursday 2 May 2013

Article 1: My take on the current Portal Industry and various Job roles


In this article I will try to briefly sum up my experiences, so far, with the Portal and some of the confusions surrounding it.
Its a bigger topic and I might use some other posts to cover this. But here is a gentle introduction.

Around 5-6 years back when I started on my first Portal project the market was picking up and was a buzz with Portal solutions such as Liferay.
It was understandable because Portals allowed a company to make better websites and at the same time display aggregated content.
I don't see much difference even today except that the Portal market is growing and getting better each passing day. The only problem is
lack of support and good resources to meet the current market needs. So while Liferay has become stronger in all these years, thanks to
a ton of features and being open source, its not quite easy to find good resources who can help customize it for specific needs.


New Series of articles on Portal and Portlets


It has been quite a while since my last Post. During all this time I had the opportunity to work with several portal projects for various clients. In the next series of posts I will try to share my experiences so far, on various Portal and Portlet related topics.
I believe most of you must be using the new JSR 286 spec to create Portlets, so in the examples that I will present I will try to use this spec.
I will try to consolidate this Post with all the articles that I will publish for easy navigation. So it might be helpful to just  bookmark this Post.

List of articles:

Article 1: My take on the current Portal Industry and various Job roles

Comparing Servlets and Portlets Part 1 : Understanding the similarities and differences

Comparing Servlets and Portlets Part 2 : Using RequestDispatcher