Liferay ist zum sechsten Mal in Folge ein Leader im Gartner Magic Quadrant. Hier mehr erfahren
« Zurück zu Development

Scripting Language 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


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 Anhänge
65528 Angesehen
Durchschnitt (0 Stimmen)
Die durchschnittliche Bewertung ist 0.0 von max. 5 Sternen.
Antworten im Thread Autor Datum
When are you going to be explaining the PHP... dennis monsewicz 30. Juli 2009 14:28
Is it possible to make a django portlet (python)? Marcelo Ruiz Camauër 30. August 2010 15:46

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.
Gepostet am 30.07.09 14:28.
Is it possible to make a django portlet (python)?
Gepostet am 30.08.10 15:46.