Apache Pluto & Groovy Integration Tutorial Example

Apache Pluto provides you a vast amount of integration types that you could use when it comes to deal with the Portlet development missions. We’ve previously, introduced you different types of Portlets; Standard Portlet (JSR286), JSP & Servlet, JSF 2.0, Struts 2.0, PHP 5 and now a Portlet of type Groovy.

Groovy is a Java Virtual Language (JVM) that’s working inside a JVM seamlessly like any Java Class you may write. Apache Pluto provides you a Groovy Bridge that enables you exposing a Groovy Portlet into your Portal Page without any need for additional cosmetics.

This tutorial is intended for providing you a full-fledged example for registering employees, in which an initial page will be displayed for employee’s information gathering. Once the user has submitted the form the employee registration will start and the confirmation message will be displayed too.

Project Structure

This figure below should help you recognize one of the best location for putting your Groovy classes as well as showing you the different accompanies files for the project.


Employee Table

As being we have a registration employee form, let’s look at the form of the Employee Table and its relevant columns.

As also, you can use below SQL create statement to get Employee Table created into your Schema.


Employee Model

In the MVC design pattern and according for the concept of Separation of Concern, we must have an Employee Model that it takes the form of:


This model will hold the data that’s going back and forth between the different components defined in the application.

Install Groovy Plugin Into Your Eclipse

To make sure you’re able of getting Groovy sources inside your Maven project, you must install Eclipse Groovy Plugin into your Eclipse IDE.

Installing of Eclipse Plugin wouldn’t take much time as you can do that by using the Eclipse install new software facility.

  • From help menu, choose Install New Software.
  • Paste copied link into Work with input and waiting until Eclipse show you the listed supposed updates that plugin contains.
  • Select Groovy-Eclipse (Required) & Click next.
  • Proceed until your eclipse has installed the Groovy Plugin and restart your Eclipse to make sure your installed Plugin takes effect.
  • Now, from your Maven Project (That you’ve created before), create a Groovy class normally.
  • Groovy-Portlet-Project-Structure

RegisterEmployeePortlet Groovy Portlet

RegisterEmployeePortlet will be built using the same manner that’s happened inside our introduced JSP & Servlet example. One major difference that it’s now a Groovy class, where no need for a package declaration nor for a variable types.

You may write a code analogous for what you’ve written inside your RegisterEmployeePortlet Java class, but for make a distinction we removed those optional constructs that Groovy doesn’t require.


Here’s detailed explanation for the code mentioned above:

  • RegisterEmployeePortlet Groovy class doesn’t reference a package, as it’s contained inside your resources in the Project Structure above.
  • Groovy is a dynamic language, and so, it’s applicable for you to miss out in the variable types. Alternatively, you must use a def keyword and the Groovy engine would expect the type of the variable from the context.
  • Groovy class is also able of accessing any defined Servlet inside your application.

RegisterEmployeePortlet Groovy Portlet Descriptor

As you’ve already used a Groovy class for creating a Portlet to be consumed by Apache Pluto, you know that the Portlet must be mentioned in the Portlet deployment descriptor (Portlet.xml).

The definition of Groovy Portlet inside your Portlet descriptor is little bit different as it’s also contained for additional detailes you must be aware of. Let’s first look at the Portlet.xml and see what are the major differences.


Here’s detailed explanation for the code mentioned above:

  • Your Groovy Portlet should be of org.apache.portals.bridge.groovy.GroovyPortlet class.
  • You must provide the script-source which will be used later on for specifying the Groovy class that’s responsible of handling the initiated Portlet request.
  • You have the ability of providing an optional auto-refresh parameter for enabling applying your modifications instantly. So, just make your modification and refresh the Portlet to get it executed directly.
  • Script-source parameter accepts different types of paths; full physical file, url, uri or by using the reserved keyword classpath as be shown.

Application Deployment Descriptor & Maven Build File

There is no any change on the web deployment descriptor, the same file is used as it’s defined in the JSP & Servlet Tutorial.


Just note that Apache Pluto assemble plugin will add some fragments into your web.xml while it builds the application for making the Portlet accessible.

At the other hand, the all required dependencies are maintained by the Maven build file, look below at the used pom.xml.


EmployeeDAO & ConnectionUtility – Database Handling



RegisterEmployeeServlet – Business Handling

If you have noticed that the Groovy class hasn’t provided any code relevant for the registration process, on the contrary, it’s used mainly for handling the required business delegation and the actual work of employee registration got defined inside our RegisterEmployeeServlet, that’s applying the concept of Separation of concern (Soc). Look at below:


JSP Views

As you’ve noticed above, your Groovy Portlet has delegated the control into three different JSP pages:




Employee Registration Demo

Before getting started demonstrate the employee registration sample, you must have an installed instance of Apache Pluto as well as a JournalDev Portal page. If you didn’t create it before, you need to return back into Apache Pluto Introduction for getting everything done.


And you should be able of seeing a new Employee saved against your database:


And if you’ve tried to register the user with the same used ID, you should be able of seeing a message tells you the actual cause of error.

Employee-Table (2)


Groovy is a dynamic JVM language, it’s amazing as you don’t need to be aware of a lot of things you must be aware of when you’re going to use Java language. If you want a Portlet that provides you the maximum gauge of Dynamicity, choose the Groovy as you can change your classes while your JVM is running.

Contribute us by commenting below and find below downloaded source code for your practice.

By admin

Leave a Reply

%d bloggers like this: