Ruby, PHP and now ... ¡Groovy!

Hi everyone.

Yes, now you can develop portlets using groovy, and thanks to the last changes made by Brian is quite simple.

Let's take a look at sample-groovy-portlet (check it out from the plugins svn). The file structure is like this:

Sample groovy porlet directory structure

All the impotant files are under docroot/WEB-INF. There you can see usual files, including portlet.xml, which looks like this

<portlet-class>com.liferay.util.bridges.groovy.GroovyPortlet</portlet-class>
<init-param>
<name>view-file</name>
    <value>/WEB-INF/groovy/view.groovy</value>
</init-param>
<init-param>
<name>action-file</name>
<value>/WEB-INF/groovy/action.groovy</value>
</init-param>
<init-param>
     <name>global-files</name>
<value>/WEB-INF/groovy/global/LiferayPortlet.groovy,/WEB-INF/groovy/global/Custom.groovy</value>
</init-param>

In this file you can set up the portlet class (com.liferay.util.bridges.groovy.GroovyPortlet) and which files will handle several options. You can specify which groovy file will be invoked to process the action and which file will be used to render the different portlet modes (in this example only the view mode is defined, but you can easily imagine how to do it for edit and help modes). You can also define a list of files including common stuff under the 'global-files' init param. You can set as much files as you want.

From groovy files you can access the usual portlet objects, namely the request and response objects (actionRequest/actionResponse, renderRequest/renderResponse), portlet config (portletConfig), portlet context (portletContext), portlet preferences (portletPreferences) and user info (userInfo).

Just one final note. You need to include groovy.jar in the lib directory of every plugin you develop.

Now you only need to write your groovy code and deploy it (if you create the plugin with the plugins SDK everything will be much easier).

Enjoy it!