Wednesday, December 23, 2009

Create Account Hook in Liferay... Dump the Ext Env!

Although I love the Extension Environment in Liferay, many of my colleagues do not so now that things have slowed down a bit I've been implementing more with hooks in v5.2.2. Ray Auge wrote some interesting information so that combined with the WOL portlet, I set out to hook some changes for creating an account. This was truly fast and easy (not to mention a god send) so here's a simple working example...

Create a portlet. So in your WEB-INF directory you will have the usual files liferay-display.xml, liferay-portlet.xml, portlet.xml, and web.xml. In my source folder I created a HooksPortlet.java file too. In the pages directory I created a view.jsp which for now just displays a message saying the portlet exists.

Create another class file (I called CreateAccountHook.java) and dump the following in to it:

package net.blah.hook.createaccount;
import com.liferay.portal.ModelListenerException;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.ModelListener;
import com.liferay.portal.model.User;
/**
* This hook intercepts the account creation process AFTER the account has been created.
*/
public class CreateAccountHook implements ModelListener {
public void onAfterCreate(BaseModel arg0) throws ModelListenerException {
User uzer = (User)arg0;
System.out.println("\n\t--------------- New user is uzer: "+uzer.getEmailAddress()+" with id of: "+uzer.getUserId()+"\n\n-------------------------");
}

public void onAfterRemove(BaseModel arg0) throws ModelListenerException { }
public void onAfterUpdate(BaseModel arg0) throws ModelListenerException { }
public void onBeforeCreate(BaseModel arg0) throws ModelListenerException { }
public void onBeforeRemove(BaseModel arg0) throws ModelListenerException { }
public void onBeforeUpdate(BaseModel arg0) throws ModelListenerException { }
public void onBeforeAddAssociation(Object arg0, String arg1, Object arg2) throws ModelListenerException { }
public void onAfterRemoveAssociation(Object arg0, String arg1, Object arg2) throws ModelListenerException { }
public void onAfterAddAssociation(Object arg0, String arg1, Object arg2) throws ModelListenerException { }
public void onBeforeRemoveAssociation(Object arg0, String arg1, Object arg2) throws ModelListenerException { }

}

Next create a file called liferay-hook.xml and dump the following into it:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 5.2.0//EN" "http://www.liferay.com/dtd/liferay-hook_5_2_0.dtd">

<hook>
<portal-properties>my-portal.properties</portal-properties>
</hook>

Note: You can call the .properties file whatever you want.

And lastly, the my-portal.properties file has to be in the WEB-INF/classes directory when it's delivered in the war. Place the following in the properties file:

value.object.listener.com.liferay.portal.model.User = net.blah.hook.createaccount.CreateAccountHook

Build the portlet and install it into Liferay. Create an account and you will see the system.out displayed in the console.

Enjoy!

Thursday, December 3, 2009

Liferay 5.2.3 and the Chat Portlet - Fixed (Inc IE6)

You may have experienced some UI difficulties using the Chat Portlet in Liferay 5.2.3. The fixes listed here are for both IE6 and other browsers.

IE 6 Snapshot





The following css classes need to be set or IE 6 will make the chat window, settings, and online friend's font text white. (Place at the bottom of theme's custom.css file.)


/*Chat Portlet fixes*/
/*Font colors are all white in IE 6*/
.ie6 .buddy-list .panel-content div { color: #000;}
.ie6 .panel-output .blurb { color: #000;}
.ie6 .chat-portlet .chat-settings .settings { color: #000;}
.ie6 .panel-profile { color: #000;}




Status messages appear behind the image in the chat window and long status messages aren't viewable properly. This is a general browser issue and not only applicable to IE 6.


IE 6 & FF Snapshot - Before

/*Long status messages appear behind the image in the chat window*/
.panel-profile { position: relative; height: 30px; left: 60px; overflow: auto; width: 166px; text-indent: 0px; }



IE 6 & FF Snapshots - Fixed




Long status messages do not display properly in the chat bar. This is applicable in all browsers.


FF Snapshot

The major problem with this is that the settings and open chat windows are pushed to the bottom and can't be accessed.

.chat-status .status-message { width: 500px; }

You'll also need to hide the overflow in IE 6

.ie6 .chat-status .status-message { overflow: hidden; height: 15px; }

The iframe class lfr-shim may be on top of our status bar so we'll have to hide it (IE 6).

.ie6 .lfr-shim { display: none; }

Of course there are other tweeks that can be done such as putting a background image of an ellipses after the truncated status message but this should suffice if you're looking for a bare-bones solution.

Tested on IE 6, 7, 8 (compat+non-compat), FF, Safari