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:-

Sending Mail in Liferay Using Templates(tmpl) Files


In the Previous blog we see how to we Configure mail in Liferay  and how to send a mail programmatically. When we send a mail we have to provide content in setBody() method either in plain text or in the HTML format. But what happen if we want to send a mail with dynamic content in body part and in proper HTML format.In this case we create templates with HTML tags and just call the tmpl files and replace the variables declared inside tmpl files with actual data.

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:-Create Template in the Project
Create a folder content inside src .After that inside this create a file with name exam.tmpl and paste this content .


Explanation:-
Here in this file we create a complete HTML structure and declare 3 variables NAME , RESULT ,PERCENTAGE and EXAM which we can set programmatically.




Step 3:-Use the Template 
Open your Controller ie java file and Paste this:-


Explanation:-
Inside sendMailUsingTemplate method we fetch the tmpl file using ContentUtil Class and then replace the 4 variables with our values.

Step 4:-Check Output 
As sendMailUsingTemplate method is called in doView method just deploy the portlet and add to page and check your inbox .You will receive a mail as:-



Project Structure:-







Hope this will Help....

You can Download Source code from  Sending Mail Using Templates.

Related Post:-

Sending Mail in Liferay Programmatically


In the Previous blog we see how to we Configure mail in Liferay.In this blog we will see how to send mail programmatically . Sending mail in Liferay is very simple we just need to use MailServiceUtil class that is provided by Liferay .Here we Consider 3 Scenario:-

So lets start :-


Scenario 1:-Send Mail With Plain Text
Create a method in your class as:-


Explanation:-

Here FromAddress should be same email address that is used in Configuration.

Output:-







Scenario 2:-Send Mail With HTML Text
Create a method in your class as:-


Explanation:-
Here we use two things:-

  • In mailMessage.setBody("") we use HTML tags.
  • And setHTMLFormat(true).

Output:-


Note:-  If you setHTMLFormat(false) than mail is sent successfully but the HTML tags are print as normal Text.

Scenario 3:-Send Mail With Attachment
Create a method in your class as:-


Explanation:-
Here we are using addition method addFileAttachment that take two arguments first is File object and second is Name that you want to given to attachment.

Output:-







Hope this will Help....

Related Post:-

Modify Email Notification Send by Liferay


In the Previous blog we see how to we Configure mail in Liferay.In this blog we will see how to modify/edit email notification send by Liferay. Liferay uses some tempelates to structure or design the mails body we just need to Change it.

So lets start this step by step:-


Step 1:-Change Template
Go to Admin->Control Panel->Portal Setting->Email Notification



Here you have 5 options:-

  • Sender
  • Account Created Notification
  • Email Verification Notification
  • Password Change Notification
  • Password Reset Notification.




Here i change the Sender Name from Test Test to Liferay Is Easy.
Now Click on Account Created Notification :-


Now Change this using WUSIWUG editor as:-



Step 2:- Check Output
Sign Out from admin and click sign in button .Now Click on Create Account and fill the form now check your mail you will get a mail as:-




The Red Color boxes represent our modification.





Hope this will Help....

Related Post:-

Mail Configuration in Liferay using Gmail


To we will discuss how to Configure Mail in Liferay so that when someone Create Account or forget Password a email notification is sent to his mail id. For Configuration mail in our Liferay we use Gmail .

So lets start this step by step:-


Step 1:-Configure Mail
Go to Admin->Control Panel->Server Administration->Mail






Provide the Configuration as Shown in the images just change the User Name with your Gmail Id and Click save.




Step 2:- Check Configuration
Sign Out from admin and click sign in button .Now Click on Create Account:-



Now Provide the fields as:-



and Click save. Now open your mail you will receive a mail as:-



In the next blog we will see how to customize this email notification that is sent by liferay.





Hope this will Help....

Related Post:-

Creating Tabs Using Web-Content /Journal Article in Liferay


In the previous tutorial we see how to embed a Asset Publisher Portlet in Liferay. Today we use the same concept and create a web content which contain 2 tabs and in each tabs we embedded a Asset Publisher portlet. Before reading this blog you must know how to create Structure and Template for Web Content and how to embedded a portlet in web content.

So Lets start this step by step:-

Step 1:-Learn How to Create Tabs
So first we see how to create tabs using YUI.


Explanation:-

  • Here you can see that href value(foo) and div id(foo) are same.
  • Number of <li> is equal to number of <div>.
  • For More details you may refer here.




Step 2:-Create Structure
We already know for embedding a Instanceable portlet we required PortletId and Instanceid . So in our structure we create 3 fields Tab Name, PortletId and InstanceId.

Go to Admin->Content->Manage->Structure->Add. 
And provide name as Tabs-Structure and Click on Source and paste this:-


Now Click on view you can see the Structure as:-



Explanation:-

  • For Tab Name Repeatable is Yes so that we can create multiple tabs.
  • PortetId and InstanceId fields are inside Tab Name so that each tab has instanceId and PortletId which is useful to embedded different Asset Publisher in different tabs.


Step 3:-Create Tempelate
Go to Admin->Content->Manage->Templates->Add. 
And provide name as Tabs-Template .Select structure as Tab-structure which is created in step 2 and from language select velocity. Now paste this:-


Explanation:-

  • Here we are iterating the tab name as we declare this as Repeatable coz we don't know on run time how tabs are created.
  • We also give href value and div id same as tab name.
  • For content inside a div we embedded a portlet by using portletId and instanceId .

Step 4:-Create Web Content using Structure and Tempelate
Go to Admin->Content->Web Content->Add->Tab-Structure.
Provide name as Multiple Mobiles .



Note:-
If you already have Asset Publisher Portlet than use the instance Id .Otherwise fill in the form and Asset Publisher portlet Created with id Sony and Nokia.

Step 5:-Check Output
Now Add this Multiple Mobiles portlet on the page and configure the Asset Publisher portlet in Nokia tab for showing Web Contents that have Nokia Category and Asset Publisher portlet in Sony tab for showing Web Contents that have Sony Category.









Hope this will Help....

Related Post:-

Embedding a Portlet in Web Content/Journal Article


We already know how to create a Web Content in Liferay. Today we will embedded a portlet in web content. We know that there are two types of portlet:-

1)Instanceable Portlet
 Instanceable portlet are those portlet that can be added more than one time on a single page. Ex- Asset Publisher.

2)Non - Instanceable Portlet
Non - Instanceable portlet are those that can be added only single time on a page. Ex- Loan Calculator.

We can embedded both type of portlet in web content by using portlet id and instance Id.




How do we get Portlet Id ?? 

Their are two ways:-

1)By portlet-custom.xml
Go to ..\webapps\ROOT\WEB-INF\portlet-custom.xml this file contain all OOTB portlet entries. You can get the Portlet Id from this file.

2)By Using Configuration
Add portlet on the page click on wrench icon and Click on Configuration.




than click on sharing


Here 101 is Portlet Id of Asset Publisher Portlet and abcd is instance id. Each Asset Publisher portlet has same portlet Id and different instance Id.

Non-Instantceable portlet has only portlet Id but not contain any instance id. Ex- Loan Calculator Portlet.

Here 61 is the Portlet Id of Loan Calculator Portlet.

For embedding a portlet we use basic xml tag provided by liferay:-



So lets embedded both types of portlet one by one.

A)Embedded Instanceable Portlet in Web Content
First Go to your home page and add Web Content Display portlet on Page. Then Click on Add


After that provide title and source as:-


and Click Publish. Now See the output:-



B)Embedded Non-Instanceable Portlet in Web Content
Now similarly add Web Content Display portlet and click add and provide title and Source as:-


Now Click Publish and see the output as:-