Monday, July 8, 2013

IPC (Inter Portlet Communication) - in Liferay.

Hi Liferay Developers,

Liferay have so many good feature. IPC is one of them. let me give basic idea about IPC. Basically
IPC is use for Inter Portlet Communication between portlets.

IPC can be achieved in two ways:

1) Public-render-parameter
2) Event-definition




1) Public Render Parameter - IPC

Adding below property in portlet-ext, we can enable portlets to share render states with other portlets that are on different pages:

Changes in portal-ext.properties:

portlet.public.render.parameter.distribution=ALL_PORTLETS



Changes in Pitcher Portlet

Step 1:

Add below attribute in Pitcher Portlet in portlet.xml

<portlet-app>
   <portlet>
         <supported-public-render-parameter>
          name
          </supported-public-render-parameter>
   </portlet>
   <public-render-parameter>
           <identifier>name</identifier>
           <qname xmlns:x="http://ktn.com/anything">x:param1</qname>
    </public-render-parameter>
</portlet-app>

Note: http://ktn.com/anything is userdefine url which you like. i.e. http://testorganizationcom/name


Step 2:
Set render parameter in the processAction() method from the Pitcher Portlet.

public void processAction(
    ActionRequest request, ActionResponse response)
             throws IOException, PortletException {
        response.setRenderParameter("name", "value");
}



Step 3:
Changes Catcher Portlet in portlet.xml, defines which render parameter is shared in portlet section.

<portlet-app>
     <portlet>
              <supported-public-render-parameter>
              name
                </supported-public-render-parameter>
     </portlet>
     <public-render-parameter>
                <identifier>name</identifier>
                <qname xmlns:x="http://ktn.com/anything">x:param1</qname>
     </public-render-parameter>
</portlet-app>


Step 4:
Portlet can read public render parameter using from the Catcher Portlet:

request.getPublicParameterMap()

or can also be read using

request.getParameter(“name”);



2) Event : IPC

Adding below property in portlet-ext, we can enable portlets to share Even states with other portlets.

Changes in portal-ext.properties:

portlet.event.distribution=ALL_PORTLETS



Changes in Pitcher Portlet

Step 1:

Adding attribute in Pitcher Portlet in portlet.xml

This is defines supported-publishing from the pitcher portlet.

<portlet-app>
     <portlet>
                  <supported-publishing-event>
                           <qname xmlns:t="http://liferay.com/events">t:name</qname>
                  </supported-publishing-event>
      </portlet>
       <event-definition>
                  <qname xmlns:t="http://liferay.com/events">t:name</qname>
                  <value-type>java.lang.String</value-type>
      </event-definition>
</portlet-app>

 
Step 2:


Changes in jsp page to

<portlet:actionURL name="myAction" var="actionURL">
</portlet:actionURL>

<a href="<%=actionURL.toString()%>"> Click here </a>

this code is generate event from jsp to controller class of Pitcher portlet.


Step 3:
By using below code line we can communicate between Pitcher and Catcher Portlet.
This is to how we sending event from Pitcher to Catcher portlet.


public void myAction(ActionRequest actionRequest,ActionResponse actionResponse) {
       QName qname = new QName("http://liferay.com/events","name");
       actionResponse.setEvent(qname,"Hello World");
       return;
}


Changes in Catcher Portlet

Step 4:
Adding below entry in Catcher portlet. This is defines supported-processing from the Catcher portlet.

<portlet-app>
       <portlet>          
          <supported-processing-event>
                        <qname xmlns:t="http://liferay.com/events">t:name</qname>
                </supported-processing-event>
       </portlet>

       <event-definition>
                 <qname xmlns:t="http://liferay.com/events">t:name</qname>
                 <value-type>java.lang.String</value-type>
       </event-definition>
</portlet-app>



 Step 5:

By below code line  capture the event in Catcher Portlet.

@Override

public void processEvent(EventRequest request, EventResponse response)
{
         Event event = request.getEvent();
         String name = (String) event.getValue();
         response.setRenderParameter("name", name);  
}



Step 6:
Now, we get this attribute value in jsp page of Catcher portlet.
In view page of Catcher Portlet, by this line we can get value of parameter from Pitcher Portlet.

<% String name = (String)renderRequest.getParameter("name"); %>



That's It for IPC. Enjoy the feature to communicate between portlet to portlet!!!

Wednesday, December 26, 2012

Template : some important variable in template(.vm)

Hi All,

   Many time we use webcontent OOTB functionality for our solution. for that we also use Structure/Template. here Template is render part of WebContent. so many time developer stuck with how to get value of some important properties like theme-dispaly,scopegroupid,image path, etc. so, here give some instruction for that.

1) to get instance of class (some times we can't get accesss class by serviceLocator.findService())
$portal.getClass().forName("com.liferay.portlet.dynamicdatamapping.storage.StorageEngineUtil").newInstance()   

2)currentScopegroupid 
    - $getterUtil.getLong($request.get("theme-display").get("scope-group-id"))
    - $request.theme-display.scope-group-id
3) images path in theme
    $request.get("theme-display").path-theme-images
4) themeDispaly
    $request.theme-display
5) globalScopeGroupId
    $groupId

5) find service
 $serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryLocalService")


Enjoy!!!

Wednesday, December 19, 2012

Servidce/Util classes access in template (.vm) file in Liferay

Hi Developers,

Many times you need to access services/util class in template. 

Below is some importance hits for the same.

=> Access services using findService method in Velocity(vm)

#set ($userLocalService= $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))
=>Access util class using  findUtil Method for inbuilt Util of Liferay
#set ($journalContentUtil = $utiLocator.findUtil("com.liferay.portlet.journalcontent.util.JournalContentUtil"))
=> some times you also need to access util class which is not have access in template file like StorageEngineUtil. for that you can use below approch..

#set ($util = $portal.getClass().forName("com.liferay.portlet.dynamicdatamapping.storage.StorageEngineUtil").newInstance()) 


HTH.. :))

Wednesday, December 12, 2012

Audio play in portlet using flowplayer.....



For mp3 audio file play you need below plugin swf & js file.

flowplayer.controls-3.2.14.swf
flowplayer.audio-3.2.10.swf
flowplayer-3.2.15.swf
flowplayer-3.2.6.min.js

and here is the sample code snippet to play mp3 audio file which in document library....

<< script type="text/javascript" src="/video-portlet/js/flowplayer-3.2.6.min.js"></script>

<< a href="http://localhost:8080/documents/10180/f7804b0c-9001-4f59-a7b2-45dcbceae8ca" style="display:block;width:520px;height:330px" id="unsecure">
            </a>
<< script type="text/javascript">
        $f("unsecure", "/video-portlet/flowplayer-3.2.15.swf",
                {
                    plugins: {
                        controls: {
                            fullscreen: true,
                            height: 30,
                            autoHide: false
                        },
                        audio: {
                            url: '/video-portlet/flowplayer.audio-3.2.10.swf'
                        }
                    },
                    clip:  {
                         provider: "audio"
                    }
                }
       
       
            );

        </script>


NOTE: "http://localhost:8080/documents/10180/f7804b0c-9001-4f59-a7b2-45dcbceae8ca" is a document library file url.

Monday, September 24, 2012

Connect to Another Datasource/Database Schema from Portlet with service

Hi Folks,

Many developer/client's need to separate the liferay database table and custom database table. so, here is the solution to maintain this approach. for that we maintain two data source/schema for liferay and custom database. we can achieve this by trying to  following steps -

1) portal-ext.properties

Add two connection properties for maintain two differance database source/schema. for example

###### MySQL Connection#######
## Liferay default database connection
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=root
jdbc.default.password=root

## Your new database connection
jdbc.test.driverClassName=com.mysql.jdbc.Driver
jdbc.test.url=jdbc:mysql://localhost/mytest?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.test.username=root
jdbc.test.password=root

2) ext-spring.xml

    create ext-spring.xml in docroot\WEB-INF\src\META-INF\ of you portlet to connect with other database shema default then liferay. copy the below content and paste in newly created file.
   
<<?xml version="1.0"?>
<<beans
    default-destroy-method="destroy"
    default-init-method="afterPropertiesSet"   
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
>

    <<bean id="testDataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
        <<property name="targetDataSource">
            <<bean class="com.liferay.portal.dao.jdbc.util.DataSourceFactoryBean">
                <<property name="propertyPrefix" value="jdbc.test."/>
            <</bean>
        <</property>
    <</bean>
   
   
    <<bean id="testHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration" lazy-init="true">
        <<property name="dataSource" ref="testDataSource" />       
    <</bean>
   

    <<bean id="testSessionFactory" class="com.liferay.portal.dao.orm.hibernate.SessionFactoryImpl" lazy-init="true">       
        <<property name="sessionFactoryImplementor" ref="testHibernateSessionFactory" />
    <</bean>
   
    <<bean id="testTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" lazy-init="true">
        <<property name="dataSource" ref="testDataSource" />
        <<property name="globalRollbackOnParticipationFailure" value="false"/>
        <<property name="sessionFactory" ref="testHibernateSessionFactory" />
    <</bean>

<</beans>

3) service.xml
    create entity with the parameter data-source,session-factory,tx-manager to connect other then default database. for example....
   
    <<entity name="MyTable" local-service="true" remote-service="false" data-source="testDataSource" session-factory="testSessionFactory" tx-manager="testTransactionManager">


4) service.properties

   check the entry of ext-spring.xml in \docroot\WEB-INF\src\service.properties file(some version of liferay have already this entry). if it is not there then append spring.configs properties with the value "WEB-INF/classes/META-INF/ext-spring.xml"
  
  
 At Last......

 After deploying portlet, custom portlet are able to connect with other then default database source/schema .

 NOTE :
 1)This example is  based on Liferay 6.0 and 6.0.29 tomcat bundle. you have to do specific changes in any of file(.xml) if needed based on Liferay version.
 2)While you connect with other then default liferay database source/schema. service-builder can't create automatically table in database. you have to create table manually. then after you can CURD operation for you custom table same as liferay default database.

Thursday, September 6, 2012

Liferay portal connection with various databse

Hi visitor,

here is the list of  different/various database and it's connection properties to connection Liferay portal.

 MySQL

jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=
jdbc.default.password=


 Oracle

jdbc.default.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.default.url=jdbc:oracle:thin:@localhost:1521:xe
jdbc.default.username=lportal
jdbc.default.password=lportal


DB2

jdbc.default.driverClassName=com.ibm.db2.jcc.DB2Driver
jdbc.default.url=jdbc:db2://localhost:50000/lportal:deferPrepares=false;fullyMaterializeInputStreams=true;fullyMaterializeLobData=true;progresssiveLocators=2;progressiveStreaming=2;
jdbc.default.username=db2admin
jdbc.default.password=lportal


 Derby

jdbc.default.driverClassName=org.apache.derby.jdbc.EmbeddedDriver
jdbc.default.url=jdbc:derby:lportal
jdbc.default.username=
jdbc.default.password=


 Hypersonic

dbc.default.driverClassName=org.hsqldb.jdbcDriver
dbc.default.url=jdbc:hsqldb:${liferay.home}/data/hsql/lportal
dbc.default.username=sa
dbc.default.password=


 Ingres

jdbc.default.driverClassName=com.ingres.jdbc.IngresDriver
jdbc.default.url=jdbc:ingres://localhost:II7/lportal
jdbc.default.username=
jdbc.default.password=


 P6Spy

jdbc.default.driverClassName=com.p6spy.engine.spy.P6SpyDriver
jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=
jdbc.default.password=


 PostgreSQL

jdbc.default.driverClassName=org.postgresql.Driver
jdbc.default.url=jdbc:postgresql://localhost:5432/lportal
jdbc.default.username=sa
jdbc.default.password=


 SQL Server

jdbc.default.driverClassName=net.sourceforge.jtds.jdbc.Driver
jdbc.default.url=jdbc:jtds:sqlserver://localhost/lportal
jdbc.default.username=sa
jdbc.default.password=


 Sybase

jdbc.default.driverClassName=net.sourceforge.jtds.jdbc.Driver
jdbc.default.url=jdbc:jtds:sybase://localhost:5000/lportal
jdbc.default.username=sa
jdbc.default.password=

Sunday, August 5, 2012

Drop all tables from users schemas in Oracle

Many times we need to clear/delete all TABLE from users schema.We can't directly delete all table.it is tedious task to delete table one by one by command. here is short way to do this.

Execute following statement which will create drop query for every table.

SELECT 'DROP TABLE ' || TABLE_NAME || ' CASCADE CONSTRAINTS;' FROM user_tables;

Now, analyze results and copy appropriate statements, paste and execute them against the database.

This is the simple way to delete all tables from user's schema.


This approach can also be used in order to drop all SEQUENCE from user's schema.

SELECT 'DROP SEQUENCE ' || sequence_name || ';' FROM user_sequences;


That's it. enjoy...!!!