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

Java Portlet Specification (JSR 168 vs JSR 286)


Initially portal vendors had their own portlet frameworks but the problem is those portlets are specific to portal Server and cannot be deployed to another server.So their is specification or we can say Standards for portlet development. By using those standards you can write a portlet which can be run on all compliant portlet Containers.



Their  are basically two JSR standard for portals:-

1)Java portlet specification 1.0 ie JSR-168

JSR-168 released in 2003 and give standards for :-

  • Portlet API.
  • Portlet Taglib
  • Portlet Life Cycle
  • Window States
  • View Prefrences


This specification introduced two phases:
  • Render Phase
  • Action Phase



2)Java portlet specification 2.0 ie JSR-286

This specification introduced two extra phases so now we have 4 phases:-

  • Render Phase
  • Action Phase
  • Event Phase for IPC
  • Resource Serving phase for Ajax calls.

Features in JSR-286:-

1)Portlet filter is introduced .
2)Annotation support in Generic portlet.
3)Generate non mark up content like images, pdf using Resource serving phase.
4)Interportlet Communication is easily handled using Events.


Hope this will Help....





Related Post:-

Database Migration From Liferay 6.1 to Liferay 6.2


Today we will discuss how to migrate database (users, roles,pages, webcontent etc) from Liferay 6.1 to Liferay 6.2. I assume that you already installed Liferay 6.1 and created pages , roles and user. The name of the database we are using for liferay 6.1 is named as liferay6.1db.

So lets start this step by step:-


Step 1:-Take backup of your database
As a precaution take backup of your database ie liferay6.1db so that if anything goes wrong your have your original database.

Step 2:-Install liferay 6.2 with hypersonic
Install liferay 6.2 and use hypersonic databse which is provided by liferay.

Step 3:-Replace document library folder
Now copy content from document_library folder of liferay 6.1 (..\liferay-portal-6.1.2-ce-ga3\data\document_library) and paste in liferay 6.2(..\liferay-portal-6.2.0-ce-ga1\data\document_library).

Step 4:-Change portal-ext.properties
Now open portal-ext.properties file and point database entry to liferay 6.1 database ie liferay6.1db.

You have to change algorithm also which is used in liferay 6.2



Step 5:-Restart the Liferay 6.2 Server
Now restart your server .You can see migration activity on the console of your tomcat . Thats it your database migrated successfully from liferay 6.1 to 6.2.

By using this approach you can migrate:-

  • User
  • Roles
  • Pages
  • Structures and Templates
  • Web Content.



Note:-  

If this error comes:-

Then open data base table portletprefrences and change NULL to some text like "Change to Not Null by me"

And Restart Server.




Hope this will Help....


Related Post:-

Quartz Scheduler in Liferay


Today we will discuss about Schedular in Liferay. Sometime we have a situation in which we have to perform a task repeatedly after a certain period of time.Ex- Send a mail every week.

Liferay provide a simple way to achieve this.We create schedular class and provide entry of timing in liferay-portlet.xml. Time for schedular can be define by 3 ways:-

1)Using Liferay Feature

Ex-   <simple>
<simple-trigger-value>1</simple-trigger-value>
<time-unit>minute</time-unit>
</simple>  

Here in time unit we mention minute and in simple trigger value we mention 1 .This means this job run in each minute.

2)Using Property file

Ex- <cron>
<property-key>everyThirtySecond </property-key>
      </cron> 

We define key and cron expression in portlet.properties file like everyThirtySecond = 0/30 * * * * ?

3)Using Cron Expression Directly

Ex- <cron>
        <cron-trigger-value>0/15 * * * * ?</cron-trigger-value> 
       </cron>

This job runs in every 15 seconds.

Note:- For Cron Trigger Expression you may refer here.

So lets start this step by step:-


Step 1:-Create Liferay Project and Portlet
Inside eclipse IDE Click on File->New->Liferay plugin project and give the project name as schedular and click finish. After that Right Click on your project and click on New than click on Liferay Portlet. Provide class name as Demo and select MVCPortlet and click finish.

Note:-You can check the snapshots in my  blog on Portlet Configuration Page in Liferay.



Step 2:-Create Schedulars
Inside com.test package create 3 classes that implements MessageListener inteface and provide the definition of receive method.

FirstSchedular.java



SecondSchedular.java



ThirdSchedular.java



Step 3:-Provide timing in liferay-portlet.xml
Open liferay-portlet.xml and paste this:-


Explanation:-
Here we provide the entries of all 3 Schedulars.



Step 4:-Create portlet.properties
Inside docroot/WEB-INF/src create portlet.properties and paste this:-

everyThirtySecond = 0/30 * * * * ?

because second schedular take value from property file.





Step 5:-Check output
Deploy the portlet and add to page:-


Now check eclipse console




Project Structure









Hope this will Help....

You can Download Source code from  Schedular in Liferay.


Related Post:-

Send Redirect in Liferay


Today we will discuss how to redirect from a portlet to another portlet which are placed on some other page. For this we need two things:-

1)Portlet Layout Id(plid)
We need the plid of the page where we want to redirect.We can get the plid by the page name as:-



2)Portlet Name
We can get the Portlet name (on which we have to redirect) by clicking on wheel icon of portlet than go to look and feel and than click on advance Styling.




So lets start this step by step:-


Step 1:-Create Liferay Project and Portlet
Inside eclipse IDE Click on File->New->Liferay plugin project and give the project name as send-redirect and click finish. After that Right Click on your project ie send-redirect and click on New than click on Liferay Portlet. Provide class name as Demo and select MVCPortlet and click finish.

Note:-You can check the snapshots in my  blog on Portlet Configuration Page in Liferay.


Step 2:-Change view.jsp
Open view.jsp and paste this content:-


Explanation:-
Here we create a simple form on submit of form sendAction method is called inside controller.


Step 3:-Create Second Portlet
Right Click on project and click on New than click on Liferay Portlet.Give Portlet Name as Result and also change jsp name to result.jsp.


Step 4:-Deploy Result Portlet
Deploy the Result portlet and add to any page in my case i am adding this to a public page named about. Now get the Portlet name by going to look and Feel as discussed above. In my case the portlet name is result_WAR_sendredirectportlet.



Step 5:-Change Controller of Demo Portlet
Open Demo.java and Paste this Content:-


Explanation:-

  • Here first we get the plid and than create a URL and send redirect to another page using plid.
  • we also send a parameter so that this can be used in another portlet.
  • For more detail on LayoutLocalServiceUtil you may refer my blog add Portlet and Change Layout Programmatically.

Step 6:-Change result.jsp
Open result.jsp and paste this:-


Explanation:-
Here we just print the value that is set in Demo.java .



For Output


Now deploy both Demo and Result portlet and add Demo Portlet to welcome page and Result Portlet to about page .

When you click on submit it will redirect to Result Portlet which is placed on about page.


Project Structure



Hope this will Help....

You can Download Source code from  Send Redirect in Liferay.











Related Post:-

Portlet Configuration Page in Liferay using Custom Class


We already discuss about Portlet Configuration page using DefaultConfiguration class provide by liferay. In this blog we create the same application but by using our own custom class.Here we are created a simple table where user can configure number of columns at run time. ie Show/Hide columns at run time.

So lets start this step by step:-

Step 1:-Create Liferay Project
Inside eclipse IDE Click on File->New->Liferay plugin project and give the project name as configure-table and click finish.






Step 2:-Create MVC Portlet inside project
Right Click on your project ie configure-table and click on New than click on Liferay Portlet. Provide class and package name and select MVCPortlet and click finish.

Note:-You can check the snapshots in my previous blog on Portlet Configuration Page in Liferay.


Step 3:-Create Configuration Jsp
Open html/demo package and create a jsp with name configuration.jsp and paste this content:-


Explanation:-
Here we just create a simple form with 4 check box. We create a actionUrl with portletConfiguration="true" so that it will call Configuration class processAction method and not of portlet processAction method.

Step 4:-Create Configuration Class
Open com.demo package a create a java class with name ConfigurationAction that extends DefaultConfigurationAction
Now override the processAction() and render() as:-


Explanation:-
1)Here we just fetch the values and set in Preferences.
2)Render method just redirect the flow to configuration.jsp.
3)The last line in Action Method refresh the page so that when we go back to page new result is shown.

Step 5:-Enable SetUp tab
Provide a entry in liferay-portlet.xml so that set up tab is enable and when we click on set up tab our Configuration Class is Called. Open liferay-portlet.xml and after <icon> tag paste this

<configuration-action-class>
       com.demo.ConfigurationAction
</configuration-action-class>


Step 6:-Change the view.jsp
Open view.jsp and paste this content:-


Explanation:-
Here we just fetch the values from preferences and show the column if value is true. Here we use jstl tags so provide the jstl entries in liferay-plugin-package.properties file as :-




Step 7:-See the Output
Now deploy the portlet and add to page and see the output as:



Now Select the fields you want to show


Now go to the page
Now you can again go to configuration->set up and again select/deselect the number of columns.

Project Structure








Hope this will Help....

You can Download Source code from  Portlet Configuration Page.

Related Post:-

Portlet Configuration Page in Liferay using DefaultConfigurationAction


Portlet Configuration page in Liferay is a very handy feature by which we can store portlet related configuration at run time. Configuration page in Liferay uses preferences to store the configuration. This can be achieved by two ways:-

1)By using DefaultConfigurationAction Class.
2)By using own class that extends DefaultConfigurationAction .

In this blog we will use the first approach.Here we are created a simple table where user can configure number of columns at run time. ie Show/Hide columns at run time.

So lets start this step by step:-

Step 1:-Create Liferay Project
Inside eclipse IDE Click on File->New->Liferay plugin project and give the project name as configure-table and click finish.





Step 2:-Create MVC Portlet inside project
Right Click on your project ie configure-table and click on New than click on Liferay Portlet. Provide class and package name and select MVCPortlet and click finish.



Step 3:-Provide Configuraion Action Class
Open liferay-portlet.xml file and provide the entry of configuration action class as:-

<configuration-action-class> com.liferay.portal.kernel.portlet.DefaultConfigurationAction
</configuration-action-class>

Now your liferay-portlet.xml become:-


Note:- The DefaultConfigurationAction class provide all the all the functionality to store the preferences . You can see the source code for the same.

Step 4:-Provide Configuration jsp
Open html/demo and create a jsp with name configuration.jsp and paste this content:-



Explanation:-
1)We create a actionUrl with portletConfiguration="true" .
If it is false than this behave as normal actionUrl and invoke processAction() of portlet.And not invoke the action method of DefaultConfigurationAction class.

2)We give name of input field as preferences--propertyName--  this is must so that these are set in preferences.

3)We use a hidden field with name cmd and value update so that as soon as form submit page refresh automatically.

Note:- You can see the source code of DefaultConfigurationAction for the same.


Step 5:-Provide entry of Configuration jsp
Open portlet.xml and provide the entry of jsp created in previous step so that when we click set up the jsp open for configuration .

  <init-param>
<name>config-template</name>
<value>/html/demo/configuration.jsp</value>
</init-param>

Here the name must be config-template.


Step 6:-Change view.jsp
Open view.jsp and paste this:-


Explanation:-
Here we just fetch the preferences and on the basis of condition show the columns.

Note:-As we use the jstl library so add jstl jars in 
liferay-plugin-package.property file as:-




Step 7:-See the Output
Now deploy the portlet and add to page and see the output as:



Now Select the fields you want to show


Now go to the page 
Now you can again go to configuration->set up and again select/deselect the number of columns.

Project Structure







Hope this will Help....

You can Download Source code from  Portlet Configuration Page.

In the next blog we will do the same thing with our own custom class. You can see my next blog on Configuration Page using own Custom Class for this.



Related Post:-

Edit Mode in Liferay


We already know each portlet have three modes view, edit and help. In this blog we see Edit mode in detail before reading this blog you must know about Portlet Modes in Liferay.In this blog we use a simple form in edit mode where user can set his preferences that he is Vegetarian or non-vegetarian and on this basis we provide a menu of food items.

So lets start this step by step:-

Step 1:-Create Liferay Project
Inside eclipse IDE Click on File->New->Liferay plugin project and give the project name as edit-mode and click finish.



Step 2:-Create MVC Portlet inside project
Right Click on your project ie edit-mode and click on New than click on Liferay Portlet. Provide class and package name and select MVCPortlet and click next.



In the next screen check Edit in Portlet modes this will provide the necessary entry in portlet.xml and also create edit.jsp . Now Click Finish.





Step 3:-Modify your edit.jsp
Open edit.jsp and paste this content:-


Explanation:-
Here we create a simple form which contain two radio button .On the submission of form processFood method is called inside the controller.

Note:- As we are not using AUI tags so add required name space parameter is false inside liferay-portlet.xml. For more details you may refer Namespaces parameter in Liferay

Step 4:-Modify your Controller
Open your java class and paste this content:-


Explanation:-
1)In processFood method we get the foodType value that is submitted by the form in edit.jsp and than set this value in  PortletPreferences and finally send the response to view mode.
2)In doView method we get the foodType value from  PortletPreferences and set in renderRequest so that it is available on view.jsp.
3)In doView we also check the value of foodType because each time portlet load doView is called .So first time when edit Mode is not called foodType is null .

Step 5:-Modify your view.jsp
Open your view.jsp and paste this content:-


Explanation:-
Here we are get and set foodType in a variable food and check the value and on the basis of value we display the messages.

Note:-
As you see we use jstl tags in view.jsp so we have to include jstl jars inside liferay-plugin-package.properties as:-



Step 6:-Check Output
Deploy the portlet and add on page .Now click on gear icon and click Preferences:-



Now select vegetarian and click submit


You will see output as:-

Now again click on gear icon than preferences and select Non-Vegetarian and click submit.You will see output as:-





Hope this will Help....

You can Download Source code from  Edit Mode in Liferay.

Related Post:-

Portlet Modes in Liferay


By default Portlet API 2.0 provide 3 portlet modes. This means whether you use Liferay Portal, IBM WebSphere Portal or any other portal 3 modes are present.

Default modes are:-

  • VIEW
  • EDIT(Preferences)
  • HELP

In addition to above modes Liferay Provide 6 other modes :-

  • About
  • Config
  • Print
  • Edit Defaults
  • Edit Guest
  • Preview

Their are basically two steps for enable modes in Liferay:-
1)Provide entry in portlet.xml. Ex-For enable HELP mode
            <portlet-mode>help</portlet-mode>

2)Create jsp for that Mode.

So Lets enable all the modes step by step:-



Step 1:-Create Liferay Project
Inside eclipse IDE Click on File->New->Liferay plugin project



Provide Project name as modes and click finish.

Step 2:-Create Portlet inside Project
Right Click on your project ie modes and click on New than click on Liferay Portlet



Give Portlet Class as Demo and Select MVCPortlet in Superclass . Now Click Next.



By Default only view mode is selected . Now Select all the other modes and Click Finish.

Step 3:-Check portlet.xml
Just Open portlet.xml and you can see that eclipse ide provide all the entries automatically


Explanation:-
From line 48 to 56 you can see that all modes are supported.
From line 9 to 44 all init-param for jsp are also created.

Step 4:-Check Jsp files
Inside your project go to docroot/html/demo .Here you see all the jsp files with a simple message is already created as:-




Step 5:-Check Output
Deploy the portlet and add to the page. Now Click on gear icon:-



Now Click On Preferences for Edit Mode, Help for help mode etc.





Hope this will Help....

You can Download Source code from  Portlet Modes in Liferay.

In the next blog we see Edit Mode in Detail.

Related Post:-

Portlet Preferences in Liferay


Today we will discuss about Portlet Preferences in Liferay. Lets discuss some basic things about Portlet Preferences:-

  • Portlet Preferences are properties for storing basic portlet configuration data.
  • Portlet Preferences are key value pair that are stored by the portal.
  • These preferences are available via PortletPreferences interface.
  • The values are stored in portletpreferences table.


We can set preferences by two ways:-
  1)By using portlet.xml.
  2)By using PortletPreferences interface.

You can read more about PortletPreferences here.

So lets start this step by step:-




Step 1:-Create Liferay Project and Portlet
Create a Liferay Project in eclipse and then create a portlet in the Project.For theses you may refer Step 1 and Step 2 of my previous blog Here .

Step 2:-Change portlet.xml
Open your portlet.xml and after </portlet-info> paste this:-
     
  <portlet-preferences> 
        <preference>
            <name>State</name>
            <value>Delhi</value>
         </preference>
    </portlet-preferences>

Explanation:-

  • Here we create a Key State and set a value Delhi to it.
  • We can also assign multiple values to a single key which return  array when we get the values.
  • We can use as many <preference></preference> tags for each  key-value pairs.

Step 3:-Change the Controller
Open your java file and paste this:-

Explanation:-
Here we are using PortletPreferences object and add another key-value pair and by using store() we commit this. For storing key-value in database store() is compulsory.

Step 4:-Change the view
Open your view.jsp and paste this

Explanation:-
Here we just get the values from PortletPreferences object.

Step 5:-Check the Output
Now deploy your portlet and check the output as:-



Note :- You can also change the values that are set in portlet.xml by using this code:-

                String state = preferences.getValue("State", "");
                preferences.setValue("State", "UP");
                preferences.store();



Database Tables


Note :- As soon as you remove the portlet from page this entry is also removed from table portletpreferences.






Hope this will Help....

You can Download Source code from  Portlet Preferences in Liferay.

Related Post:-