Home » Devtech review » LangsNTechs » Java » Liferay » 5.2.3 » Liferay 5 portlets and expression language

Liferay 5 portlets and expression language

Portlet EL
Short starter note about Liferay 5 portlets and expression language.

Today I tried Liferay 5.2.3 for a first time, and followed a simple instruction for creating and deploying a portlet for it. If you checked it out, you know it’s like “go to plugin SDK portlets folder, run create script, go see/modify view JSP and rest of stuff in portlet folder, run ant deploy, add and see your portlet” (-: , so all seems really simple and doesn’t require any particular knowledge.

But there is one stupid thing about it.

Stub portlet files are taken from portlet.zip which resides in very same dir (i.e. ${plugins SDK home}/portlets) + some are copied from elsewhere. Among others, in portlet.zip there’s stub deployment descriptor (WEB-INF/web.xml), and it has a bit of a problem – it’s contents look like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">


This means that resulting webapp is Servlet specification version 2.3 compatible. Which means expression language is disabled by default. I.e. stuff like ${myVar} will not work – for servlet spec 2.3 expression language is disabled by default for backward compatibility.

This is dumb, because Servlet 2.3 spec is ancient, and if you check Servlet specification on Wikipedia you see it’s mentioned with J2SE 1.2 and J2EE 1.3. While Liferay 5 actually requires Java 5! (i.e. 1.5 in “traditional” versioning) Why not use Servlet 2.5 or at least 2.4 compatibility by default then?
Expression language isn’t some new fancy feature, it’s there for years, I believe it’s worth being enabled by default.

Oddly enough, there seem to be more cases of this backward compatibility freakiness: Google App Engine.

To configure your webapp to be Servlet 2.4 compatible, and thus enable expression language, replace default web.xml with this (I know you probably know this, but might be handy to copy-pase right from here ((-: ):

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"

Don’t know about you, but I’ll update it in my portlet.zip too.

UPD: Just to beat it to death completely, here’s the quote from Portlet 2.0 specification (JSR-286)

“The portlet container is an extension of the servlet container. As such, a portlet container can be built on top of an existing servlet container or it may implement all the functionality of a servlet container. Regardless of how a portlet container is implemented, its runtime environment is assumed to support at least Servlet Specification 2.4.”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s