Wednesday, February 23, 2011

Creating and Applying Different Liferay themes to Pages

Here is an example of how to apply different themes on pages in Liferay. Here we have created two themes-

1. First of all in the liferay-look-and-feel.xml file, create two different theme entries that refer to the same theme but have a different value for the header-type setting:


Both the theme entries refer to same theme but they different value for their header-type setting. We can access the settings programmatically in our theme template and then take action based on the settings we have defined.

When this theme is deployed to Liferay, it will display to the user as two different themes.

2. Accessing the settings in portal_normal.vm template file




In the above code we accessed the settings defined in the liferay-look-and-feel.xml file and based on the value of the setting we are parsing different template files.

Custom Sql in Liferay

1. Create a folder named custom-sql under the src folder.

2. Create a default.xml file in the custom-sql folder.

3. Create another xml file in the custom-sql folder, this file contains the custom sql query.

4. Create a class say SampleFinderImpl in the persistent package. This class will extends the BasePersistenceImpl<Sample> and implements SampleFinder.

5. Now build the service, it will generate the SampleFinder Interface.

6. Now define methods to execute custom sql in the SampleFinderImpl class.

7. Build the service; it will generate the SampleFinderUtil class with the method defined in the SampleFinderImpl class.

8. Copy the generated method definition from SampleFinderUtil and place it in the SampleLocalServiceImpl.

9. Build the service; it will place the methods definition in the SampleLocalServiceUtil from EntryLocalServiceImpl.



1. Create a folder named custom-sql under the src folder.


2. Create a default.xml file in the custom-sql folder.


3. Create another xml file in the custom-sql folder, this file contains the custom sql query.


4. Create a class named (EntryFinderImpl) in the persistent package. This class will extends the BasePersistenceImpl<Entry> and implements EntryFinder.


5. Now build the service, it will generate the EntryFinder Interface.


6. Now define methods to execute custom sql in the EntryFinderImpl class.


7. Build the service; it will generate the EntryFinderUtil class with the method defined in the EntryFinderImpl class.


8. Copy the generated method definition from EntryFinderUtil and place it in the EntryLocalServiceImpl.


9. Build the service; it will place the methods definition in the EntryLocalServiceUtil from EntryLocalServiceImpl.


10. Now the method is available to call from any portlet class.



Job Scheduling in Liferay 6

Following are the steps to schedule the job in Liferay 6.

1. Implement a class that will implement MessageListener Interface.



2. Then we need to tell liferay to run this job. So you add the following to your liferay-portlet.xml:


3. We need an actual portlet to attach this "scheduler-entry" to. So we also need the portlet.xml as usual.

Its Done!!!