Monday, June 18, 2012

AUI: Refresh on popup close button

To referesh the parent window while closing a AUI pop in liferay, use the following code:
window.myDialog = new A.Dialog(
            {
     on: {
      close: function() {
      document.location.href='<%=oncloseURL%>';
     }

    },
                title: title,
                centered: true,
    resizable: false,
    draggable: false,
    modal: true,
    width: 800,
    height:550,
   
       
            }
        )

Friday, June 15, 2012

Inter Portlet Coordination with JSR 286

JSR 168 (Potlet 1.0) specification doesn't clearly suggest any mechanism for the inter-portlet communication i.e. communication between two portlets. This was regarded as one of the major short-comings for JSR 168. Though most of the vendors had their own extensions to JSR 168 for managing inter-portlet communication, use of any of those methods defeat the very purpose of JSR 168. In absence of any well defined sophisticated mechanism, JSR 168 developer had to rely upon either PortalContext or Application Scope of Session for sharing information between the protlets.

JSR 286 has come up with a well defined model to achieve inter-portlet communication. There are two primary ways by which inter-portlet communication can achieved as follows -

  1. public render parameters in order to share render state between portlets.
  2. portlet events that a portlet can receive and send.


There are pros and cons of each method. Though the biggest advantage with Portlet Events method is that an object can be passed from one portlet to another as opposed to merely "String" in case of "Public Render Parameters" method.

Below are the steps to get it going:

Step 1:

Open portlet.xml and add the following entries

<portlet-app ...>
<portlet> ... </portlet>
<public-render-parameter>
<identifier>user-id</identifier> <qname xmlns:x="http://abc.com/userId">x:userId</qname>

</public-render-parameter>

</portlet-app>

Note:
  1. A developer can declare a list of public paramters for a portlet application in portlet.xml.
  2. Parameter names are namespaced to avoid naming conflict.

Step 2:

Portlet must declare which public param they want to use. e.g.

After adding declaration portlet.xml will look something like this.

<portlet-app ......>
<portlet>
<portlet-name>test1</portlet-name> <display-name>test1</display-name>
........ ........

<supported-public-render-parameter> user-id</supported-public-render-parameter>
</portlet>
<public-render-parameter>
<identifier>user-id</identifier> <qname xmlns:x="http://abc.com/userId">x:userId</qname>

</public-render-parameter>

</portlet-app>

Note: 
  1. Public params are available in all lifecycle method like processAction , processEvent, render and serveResource.

Step 3: 

We can set render parameter in the processAction() method by using the defined public render parameter identifier as the key. e.g.

public void processAction(ActionRequest request, ActionResponse response)

throws IOException, PortletException {
 ........ 
response.setRenderParameter("user-id", userId);
 }

Step 4: 

A portlet can read public render parameter using follwing method

request.getPublicParameterMap()

Note: 
  1. Public render parameters are merged with regular parameters so can also be read using

request.getParameter(name) or request.getParameterMap()

Step 5: 

A portlet can remove a public render parameter by invoking following methods.

response.removePublicRenderParameter(name)

or

portletURL.removePublicRenderParameter(name) 

References

http://blog.xebia.com/2009/04/19/inter-portlet-coordination-with-jsr-286/

Thursday, June 07, 2012

Liferay Tomcat Performance

Motive

To get performance improvement in terms of time taken by liferay tomcat to start.

Solution

Tomcat's core libraries are available in Java Byte code normally. Apache Tomcat Native Library is a Java Native Interface that provide most of the core functionality in native code. Using these libraries only mean one thing to you and i.e. SPEED.
 For Windows
  1. Download http://archive.apache.org/dist/tomcat/tomcat-connectors/native/1.1.15/binaries/win64/x64/
  2. Copy tcnative-1-ip4.dll to %TOMCAT_HOME%/bin
  3. Restart Tomcat and check the tomcat startup performance.




Tuesday, May 15, 2012

Liferay: Working with model listeners

What 

Model Listener - as the name specifies that there is some class that in continuously looking to a entity model in liferay. More technically its a call back class which is called when some operation happens on the model (operation can be add/edit/delete).

Model Listener

public interface ModelListener<T> {
 public void onAfterAddAssociation(Object classPK, String associationClassName, Object associationClassPK) throws ModelListenerException;

public void onAfterCreate(T model) throws ModelListenerException;

public void onAfterRemove(T model) throws ModelListenerException;

public void onAfterRemoveAssociation(Object classPK, String associationClassName,  Object associationClassPK) throws ModelListenerException;

public void onAfterUpdate(T model) throws ModelListenerException;

public void onBeforeAddAssociation(Object classPK, String associationClassName, Object associationClassPK) throws ModelListenerException;

public void onBeforeCreate(T model) throws ModelListenerException;

public void onBeforeRemove(T model) throws ModelListenerException;

public void onBeforeRemoveAssociation(Object classPK, String associationClassName, Object associationClassPK) throws ModelListenerException;

public void onBeforeUpdate(T model) throws ModelListenerException;
}
 

How

To implement own listener on some Model (for example User) yin your portlet you need:
<hook>
 <portal-properties>portal.properties</portal-properties>
</hook>
 
Make an entry in file WEB-INF/src/portal.properties to define hook for specific model:
value.object.listener.com.liferay.portal.model.User=my.hook.UserListener 

Implement class by inheriting it from BaseModelListener<T> in our case BaseModelListener<User> and implementing only
  method we want to call-back:

    public class GroupListener extends BaseModelListener<Group> {
@Override public void    onAfterUpdate(User u) throws ModelListenerException { // do something here } }



Rounded



Use firebug and check the style of this below black background to get the css for making corners rounded.