Showing posts with label Liferay. Show all posts
Showing posts with label Liferay. Show all posts

Wednesday, August 14, 2013

Liferay Overview



Portlets are web applications that are designed to run inside a portlet container that implements either the Portlet 1.0 (JSR 168) or Portlet 2.0 (JSR 286) standard. Portlet containers provide a layer of abstraction over the Java EE Servlet API, and consequently require a servlet container like Apache Tomcat to function.

        Portals are standalone systems that use a portlet container as the runtime engine for executing portlets. When a portal is asked to deliver a portal page to the end-user’s web browser, each portlet is asked to render itself as a fragment of HTML. It is the job of the portal to aggregate these HTML fragments into a complete HTML document.


Portlet life cycle -

Each portlet in jPortlet exhibits the following portlet life cycle.
  • init() -  When the Portal initializes, it initialized each Portlet by calling their init() method. Like Servlets, the only one instance of the Portlet is initianticiate and shared by all the users.

  • service() - The portal calls the service() method when the portlet is required to render it's content. During the life cycle of the portlet the service() method is typically called many times.  

  • destroy() - When the portal is terminating, portlets are taken out of service, then destroyed with the destroy() method. Finally the portlet is garbage collected and finalized.



In order to service users, each portlet is combine with a user session. When the user logs into the portal, the login() is called for each portlet, which allow each portlet to initialize the user portlet. The portlet call the logout() method of each portlet to inform the the user's session is terminating. 

Portlet modes  -

A portlet mode indicates the function a portlet is performing in the render method. Portlet modes allow to display different user interfaces, depending of the task required. In jPortlet, there are 4 diplay modes which can be invoked by icons on the portlet title bar. 
The following modes are supported by the Portlet API:

View - 

This is the portlet's normal mode of operation.




Help - 
If this mode is supported by a portlet, the portlet provides a help page for users to obtain more information about the portlet.



Edit - 
If this mode is supported by a portlet, the portlet provides a page for users to customize the portlet for their own needs. For example, a portlet can provide a page for users to specify their location for obtaining local weather and events. Users must be logged into the portal to access edit mode.  



Configure - 

If this mode is supported by a portlet, the portlet provides a page for portal administrators to configure a portlet for a user or group of users. The Portlet API provides methods for the portlet to determine the current or previous mode. All portlets must support the VIEW mode.

Portlet Window States - 

Portlet states allow to change how the portlet window is displayed within the portal. The following states are supported by the Portlet API: 

NORMAL - The is when the portlet is arranged with other portlets.

MAXIMIZED - When a portlet is maximized, it is displayed in the entire body of the portal, replacing the view of other portlets. The Portlet API provides methods for the portlet to determine the current state. By default, jPortlet always display the modes EDIT, CONFIGURE and HELP in MAXIMIZED state. 

Portlet events - jPortlet supports 2 type of events: 

Action events-

When a user click a SUBMIT button in the HTML view of the portlet, this click is transformed to an ActionEvent that is generated and received by the Portlet's ActionListener 




Message events -

These event are generated when a portlet send a message to another portlet. Its a basic structure for inter-portlet communication. MessageEvent are received by the target Portlet's MessageListener

Portlet Preferences - 

Developers often have the requirement to provide the end-user with the ability to personalize the portlet behaviour in some way. To meet this requirement, the Portlet 1.0 and 2.0 standards provide the ability to define preferences for each portlet. Preference names and default values can be defined in the WEB-INF/portlet.xml configuration file. Portal end-users start out interacting with the portlet user interface in portlet VIEW mode but can switch to portlet EDIT mode in order to select custom preference value.
Example 1.1. Specifying preference names and associated default values in the WEB-INF/portlet.xml configuration file.

<portlet-app>
        <portlet>
               ...
               <portlet-preferences>
                       <preference>
                               <name>datePattern</name>
                               <value>MM/dd/yyyy</value>
                       </preference>
                       <preference>
                               <name>unitedStatesPhoneFormat</name>
                               <value>###-###-####</value>
                       </preference>
               </portlet-preferences>
               ...
        </portlet>
</portlet-app>



How to create Portlet in Liferay using eclipse



Creating portlets with liferay plugin SDK is very simple. For creating a portlet we need to
have..

Here we are using below enviornment.

1) liferay-plugins-sdk-6.1.0
2) liferay-portal-6.1.1-ce-ga2
3) Juno eclipse with liferay plugins
4) Jdk 1.6_45

Let's start creating our first portlet.

Go to File → New → Liferay Project



Next, go through the following steps to setup your new portlet:

Fill in the Project and Display names with my-firstdemo-portlet and My firstdemo, respectively.
Liferay adds automatically "-portlet" at the end of the project name.





If Liferay Plugins SDK is not configured, click "configure" link and give the path of the downloaded "liferay plugin sdk".

Same if "Liferay Portal Runtime" is not configured, click "New" button and give path of the "liferay-portal-6.1.1" bundle.



Select Liferay v6.1 CE(Tomcat 7) for the server run time enviornment.




Click finish.

Now you can see the directory structure of the project. As project is created "Build Successful" message can  be seen.




Now our first default application has been created and ready to run on server. To run this project, right click on the project and select server to deploy the application.


Liferay server has already been selected and click finish button.



You can see the log on console of the eclipse.


Server is running on the "http://localhost:8080/" address.

login with the default Email Address and the password.

Email Address - test@liferay.com
Password - test






 Click on the "Add" button on the left top.


Now our portlet can be seen under "Sample tag" with the name of the "My Firstdemo". Select this and click on add next to it. This portlet will be added in the main page.


In the last image our portlet has been added.
A search portlet is already added in this page.






Congratulations!! we have successfully created and deployed our first portlet.