« Back to Development

Scripting Language Portlets

(Redirected from Scripting languages to develop portlets)

Introduction #

Liferay has support for developing portlets in Ruby, PHP, Groovy, Python, and Javascript in the plugins environment.

Developing using scripting languages is quite easy. You can use the sample portlets as reference, providing the developer the appropriated directory structure, that looks similar to

Description #

All the impotant files are under docroot/WEB-INF. There it can be found the 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, com.liferay.util.bridges.ruby.RubyPortlet, com.liferay.util.bridges.php.PHPPortlet, com.liferay.util.bridges.python.PythonPortlet, com.liferay.util.bridges.javascript.JavaScriptPortlet) and which files will handle several options. You can specify which 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 it is quite easy to 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.

The other files (info.groovy and java.groovy) represent different views your portlet may have, but they have to be linked from somewhere to be accessible. Remember to use the appropriated methods to create correct links inside the portal. For convenience, LiferayPortlet.groovy (or the appropriate one for the scripting language of your choice) includes some methods and examples about how to do that.

The way global files are handled is just by creating a large text structure made by concatenating the global files and the script to execute (view.groovy, java.groovy, ...). Consider this to properly write classes or modules qualified names.

From scripting 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). They are Java objects, so they have all methods and properties you would expect if in a Java class.

The internal implementation is done using BSF, buth some languages require special handling. Ruby uses Jruby, groovy has its own implementation, PHP requires Quercus and Python support is based on Jython. JavaScript execution in handled by Rhino. You need to include the appropriate jar file in the lib directory of your portlet.

TODO: Explain PHP portlets differences. They can be developed including only php files without the full structure and the jar file.

0 Attachments
56056 Views
Average (0 Votes)
The average rating is 0.0 stars out of 5.
Comments
Threaded Replies Author Date
When are you going to be explaining the PHP... dennis monsewicz July 30, 2009 2:28 PM
Is it possible to make a django portlet (python)? Marcelo Ruiz Camauër August 30, 2010 3:46 PM

When are you going to be explaining the PHP portlets differences? It looks as if this post has been up for quite sometime and have yet to see anything.
Posted on 7/30/09 2:28 PM.
Is it possible to make a django portlet (python)?
Posted on 8/30/10 3:46 PM.