Thursday, April 21, 2011

SEVERE: Error listenerStart Part II

Sometimes they come back...

SEVERE: Context [/mybrokenportlet] startup failed due to previous errors

Liferay 5.2

Oh yeah, so I had this one come back and give me the proverbial love bite in the derrière.

Checked all the jars: Good.
Checked all the configuration names matched the .war file name: Good.

What's left?

The scenario:

I was making a copy of an existing portlet project in order to keep the existing version which was in use in a production server and modify the copy to form a new portlet with similar functionality.

So I just took the old portlet "myoldportlet-portlet" (Names being fictionalized here to protect the innocent) and went through all the java files, all the config files, the pom.xml and updated the names using the good ol' find/replace feature.

...being oh, so careful to keep track of uppercase/lowercase.

(Pay attention, boys and girls. This is foreshadowing.)

And guess what happened when I went to deploy my new cloned portlet?

portlet was unregistered due to previous errors.

Long story short, I converted this entry in my faces-config.xml

com.my.uber.portletapp.MyOldPortletPhaseListener

to

com.my.uber.newportletapp.mynewportletPhaseListener

Yeah. Go figure Tomcat choked on it.

Case sensitivity is nothing to play with.


(If you're still having trouble, try here.)

Monday, April 11, 2011

JavaScript in Liferay Portlets! How?

So as much as I personally detest using JavaScript and prefer to handle my AJAX through ICEfaces, there are occasionally times when one absolutely must use some JavaScript. I also grudgingly admit that there are plenty of people out there for whom using JavaScript is a delight.

This post is for you.

Using JavaScript class files with Liferay portlets is easy, but it seems unusually difficult to get a simple, straightforward answer to the question "How do I link my .js files to my portlet?"

Now, the answer I've heard around the water cooler is "Stick it in the HEAD tag on your page, of course." Well if you're following best practice, your portlet has no business including a HEAD or BODY tag. Not only that, but by doing it that way you're asking for all sorts of interesting conflicts. There is a better way.

Your Liferay portlet includes, in your WEB-INF folder, a liferay-portlet.xml file, does it not?

It had better.

That's where you define your .js and .css class files for the portlet.

Inside the <portlet> element, you should have these two settings:

<header-portlet-css>
/xmlhttp/css/mysuperawesomestyle.css
</header-portlet-css>

<header-portlet-javascript>
/js/theworldsgreatestjavascript.js
</header-portlet-javascript>

With those paths and filenames being relative to the portlet's own application directory.

Have more than one file to link? Use multiple tags and define each one individually.