Monday, October 3, 2011

Inter Portlet Communication (IPC) in Liferay


A common question and topic when I do training or work on support cases, is, "What is the right way to do inter portlet communication in Liferay?"
Well, there is no "right way" to do this. At least not yet. This is because IPC was left out of JSR-168. In other words, there is no standard API. As for JSR-286, there will be a IPC standard that will be an event system. IPC is on the Liferay roadmap as well.
For the time being, here are three ways in which IPC can be implemented:

Method 1) The first is to use the request attributes to pass messages between portlets. You can also use session attributes for this as well.
Method 2) We provide a proprietary portlet url tag that allows you to target one portlet to another (cross-linking). It looks something like this:
<liferay:actionURL portletName="xxx" />
Method 3) Use our AJAX toolkit to inject content from one portlet to another. See http://wiki.liferay.com/index.php/Ajax_Toolkit for more information. You can see how you can use this in conjunction with portlet urls to inject content into a div layer.

The most recommended approach is to use (Method 1) from above, using request or session attributes.

In order for this to work you must have the portlet calling request.setAttribute() and it needs to be doing it within processAction(), so that this executes before the other portlets call render().

Once you do this IPC is complete, the other portlets can pick up the message using renderRequest.getAttribute().

AJAX vs. NON-AJAX
You will have to use a non-ajax approach if you want it to be more flexible. So basically, the trade-off is:
1) non-ajax approach is more flexible
2) ajax approach requires hardcoding of the portlet name in the JSP

What is Liferay ?


Liferay Portal is an enterprise web platform for building business solutions that deliver immediate results and long-term value.

Liferay Portal is a free and open source enterprise portal written in Java.

It is primarily used to power corporate intranets and extranets.Liferay Portal allows users to set up features common to websites. It is fundamentally constructed of functional units called portlets.

Liferay is sometimes described as a content management framework or a web application framework.

Although Liferay offers a sophisticated programming interface for developers, no programming skills are required for basic website installation and administration.

Liferay Portal is Java based and runs on any computing platform capable of running the Java Runtime Environment and an application server. Liferay is available bundled with an application server such as Apache Tomcat.

More at http://www.liferay.com/products/liferay-portal/overview

Friday, September 30, 2011

Extension


The Extension Environment allows for complete customization of Liferay.

  • Internal portlets can be modified. 
  • Liferay's .jsp pages can be changed. 
  • Customizations are kept separate from the Liferay source. 
  • The Liferay source code does not have to be modified.
  • Developers have a clear upgrade path. 
  • The combination of the MIT license and the extension environment means that organization-specific customizations do not need to be contributed back to the Liferay project.

Plugins


The Plugins SDK is a simple environment for the development of Liferay plugins.

  •  Portlet, theme and layout development used to take place in the ext environment. 
  • The ext environment no longer supports portlet and theme development, except for struts portlets and modifying/extending Liferay’s out-of-the-box portlets. 
  • The Plugins SDK is to be used instead to create hot-deployable portlets, themes and layouts.
Portlets can make use of any application framework that Liferay supports 
  • Struts 
  • JSF 
  • Spring 
  • JSP
  • MVC

Portlet Development Extension


Allows management of:
  • Configuration files 
  • Custom source code 
  • Custom JSPs 
  • Modified JSPs 
Provides different sublevels of extensibility


portal(-ext).properties

  • Main configuration options: deployment, themes, hibernate, cache, instance settings, users, groups, language, session, auth, integration, events, ... 

system(-ext).properties
Convenient way to provide and extend the Java System properties used by Liferay

  • The extension points or hooks allow creating custom classes for the most common extensibility needs 
  • Configurable through portal.properties 
  • Examples: Authentication chain, Upgrade and verification processes, Deployment processes, Database access and caching, User fields generation and validation, session events, permissions, model listeners, ext-spring.xml

Portlet Development Plugins


Types: Portlets, Themes, Layout Templates,Hooks

  • Developed as independent software components 
  • Distributed and deployed as WAR files 
  • Can be organized in plugin repositories 
  • Liferay provides the Plugins SDK to help with development of plugins.

Portlet Development Strategy



  • Overview recommended best practices for developing portlets and extending Liferay Portal's functionality. 
  • Understand the compromises involved in each of the methods. 
  • Evaluate how to combine the different methods for the needs of your organization.

Portlet characteristics


Portlets have additional characteristics that make them different from Servlets

  • Portlet Modes 
  • Window States 
  • Portlet Preferences 
Portlet Modes 
  • Each portlet has a current mode, which indicates the function the portlet is performing. 
  • All JSR 168 compliant portals should support the View, Edit and Help modes.
Window States 
  • Window states indicate the amount of portal page space that will be assigned to a portlet. 
  • All spec compliant portals should support the minimized, maximized and normal window states.
Portlet Preferences 
  • Portlets can be configured to provide a custom view or behavior for different users. 
  • For example, a weather portlet can show the temperature in Chicago for one user and the temperature in LA for another user. 
  • These configurations are represented as a persistent set of name-value pairs and are referred to as portlet preferences. 

    Portlet Lifecycle

    • Portlets are different from servlets in that they have a 2 phase commit. 
    • With servlets, the service() method processes all requests. 
    • With portlets, the processAction() method processes the requests and the render() method draws the contents of the portlet on the page.

    init() 
    • Initializes the Portlet 
    processAction() 
    • process input from a user action. 
    render() 
    • Renders the content output. 
    destroy() 
    • Cleans up the portlet 
    serveResource() 
    • Allows a portlet to serve a resource 
    • The serveResource() method can be used to implement AJAX use cases. 
    processEvent() 
    • Perform events triggered by other portlets. (IPC) 

    What is a portlet?



    1. A portlet is a web component that processes requests and generates dynamic content. 
    2. The content generated by a portlet is also called a fragment (e.g. HTML, XHTML, WML) and can be aggregated with other fragments to form a complete document. 

    What are JSR 168 and JSR 286 ?



    1. JSR 168 and JSR 286 are Portlet Specifications  
    2. They were created out of a need to have a specification for displaying multiple applications on the same page. 
    3. The specs define the lifecycle of a portlet as well as its characteristics/look and feel. 
    4. They standardize the way portlets are developed. 

    What is Liferay Portal?

    1. Liferay Portal is the world's leading open source enterprise portal solution using the latest in Java and Web 2.0 technologies.  
    2. Runs on all major application servers & servlet containers, 
    3. databases, and operating systems with over 700 deployment combinations  
    4. JSR 168 and JSR 286 compliant  
    5. Out-of-the-box usability with over 60 portlets pre-bundled  
    6. Built-in Content Management System (CMS)  
    7. Built-in Collaboration suite  
    8. Personalized pages for all users 
    9. Hot-Deployable Theme/Portlet Architecture with Online Software Catalog 
    10. Freeform / WebOS layout 
    11. Just-in-time Portlet rendering 
    12. Fine-grained permissions system