This blog has moved

to http://javaenterpriseportal.com . See you there ! 🙂

Theme’s Deployment Descriptor Generation

Last week, I had a task to modify theme’s deployment descriptor ( web.xml ) file. Since Liferay’s compression filter doesn’t work on Weblogic application server, we created our own compression filter, and need to added it to the theme, in order to enable compression for *.js and *.css files.

I thought this would be easy and simple task, just modify theme’s web.xml. But after generating the theme using plugins SDK, I realized that web.xml is not created, even though I already generated war file. So how could I modify web.xml file ?

Read more »

Language Localization

There are three ways to get localized language / text in Liferay. This is usually refers to get a value from content/Language*.properties by using a key. You can get this value from the following  files :

  1. From java class
  2. From jsp page
  3. From javascript file

Read more »

Liferay Integration with OpenSSO

Liferay integration with OpenSSO has many challenges if you never do it before. This challenges come from OpenSSO package itself, from application server (Tomcat), and from Liferay itself.

Things you have to take attention when doing integration :

Read more »

Bugs in ServiceBuilder

There are two bugs in Liferay’s 5.1.2 service builder

  1. The first bug I found is, whenever I setup ext-environment and using service builder to generate service layer without remote service (remote=”false” in service.xml). Liferay generates remoting-servlet-ext.xml file under ext/ext-web/WEB-INF with no beans at all. So generated content only <beans/> tag, since there’s no bean generated. However in ServiceBuilder.java, it always expects </beans> closing tag. This can be seen on line 2171 ServiceBuilder.java

Read more »

Changing database column size using model-hints in Liferay

I had a task to modify Liferay’s core table column size, to make the column wider. Just to make it simple, the table that was going to be modified was User_ table ( User entity as the corresponding entity ), the column was emailAddress. I wanted to change the emailAddress column width to be 100. I was thinking “What are the options to do this, and what are the consequences?”.
Read more »

How to create portlet using Plugins-SDK and Eclipse

In this article, I’ll teach you to create a portlet as plugin ( portlet plugin is a portlet that will be deployed using separate war file, quite different from ext approach). There are two ways to do this :

  1. Using Liferay’s plugins SDK
  2. Using Eclipse alone.

Let’s start

  1. Read more »

How to display journal content inside a portlet

Sometimes you want a portlet contains some texts from journal article, so user can easily edit the text. In that case you have to modify the presentation file of your portlet ( whether it’s a JSP file, VM, etc ), to display the content. You can use com.liferay.portlet.journalcontent.util.JournalContentUtil class to display the content. Assume that you use JSP for your presentation and you use ext environment for your portlet, here are the steps to do it :

  1. Include /html/portlet/init.jsp on your portlet’s JSP.
  2. Include com.liferay.portlet.journalcontent.util.JournalContentUtil in your JSP file
  3. Get your journal article’s id
  4. Call getContent method of JournalContentUtil inside the JSP

Let’s go to the details.

Read more »

Liferay Portal : How to change portlet look and feel on every page

Liferay Portal

A few days ago I had a task to update portlet title in ‘Sign-in’ Portlet, from ‘Sign-in’ into ‘myGeco for Consultant’ and the background colour to #f6f6f6. If I only used ‘Sign-in’ portlet in 1 page, then this task would be easily done by login as admin and changing the look and feel. But the problem is, I have so many pages, and almost every page is including this ‘Sign-in’ portlet. So the question is, how to update all the look-and-feel the effective way, not changing them one by one ?

Would it be possible to update directly into database ? And if possible, how to do it ?

So here are the steps to do it :

1. Create desired look and feel on 1 portlet in 1 page, save it. All the look and feel will be saved into database.

2. Find out what is the portletId, and pageId ( plid ).

3. From the database, select the portlet preference value for that portletId and pageId.

4. Update all pages that contains that portlet with new portlet preference.
On the first step, you need to update the look and feel on the portlet manually, and save it. This value will be saved into table portletpreferences, so we can use this value later to update all pages that contain that portlet.

On the second step, you need the portletid and pageid (plid) to do select from portletpreferences table. How do you find this portletid and pageid ? You can login as admin, and mouseover above ‘Minimize’ icon. You’ll find a javascript link like this :


javascript: minimizePortlet('10701', '58', false, '');

It means, the plid is 10701, the portletid is 58. Now you can do select into portletpreferences table by doing query like this :


select preferences from portletpreferences where plid=10701 and portletId='58';

Now, you’ve got the value you want, just update all the pages that contains portletId=’58’ with this value :


update portletpreferences set preferences='preferences_value_of_your_portlet' where portletId='58';

Done. Tested on Liferay 4.3.3

Sending email in Liferay Portal

Sometime in your portlet you want to have sending email capability. You can use JavaMail API, but actually Liferay already provide utility class to send email, so we don’t have to play with direct JavaMail API.

Here are the steps to send email in Liferay :

1. Configure your SMTP provider, user id, and password on your application server

2. Use the MailEngine utility class to send email.

In this article, we’ll use Tomcat as our application server, and use Gmail as SMTP. You have to add information about SMTP host, user id, and password on resource configuration file under $tomcat_home\conf\Catalina\localhost\ROOT.xml.

Comment out resource name “mail/MailSession”, and add your mailsession configuration. So the ROOT.xml would be like this :


    <!-- Commented out
    <Resource
        name="mail/MailSession"
        auth="Container"
        type="javax.mail.Session"
        mail.imap.host="localhost"
        mail.pop3.host="localhost"
        mail.smtp.host="localhost"
        mail.store.protocol="imap"
        mail.transport.protocol="smtp"
    />
    -->

   <Resource
                        name="mail/MailSession"
                        auth="Container"
                        type="javax.mail.Session"
                        mail.imap.host="localhost"
                        mail.pop.host="localhost"
                        mail.store.protocol="imap"
                        mail.transport.protocol="smtp"
                        mail.smtp.host="smtp.gmail.com"
                        mail.smtp.port="465"
                        mail.smtp.auth="true"
                        mail.smtp.starttls.enable="true"
                        mail.smtp.user="your_user_id"
                        password="your_password"
                        mail.smtp.socketFactory.class="javax.net.ssl.SSLSocketFactory"
      />

Now we go to step 2. Class com.liferay.util.mail.MailEngine has send method, which is overrided with a few arguments. If you just want to send email with body, subject, and 1 recipient, you can just use MailEngine.send(String from, String to, String subject, String body) like this :


String from = "sender@host.com";

String to = "recipient@host.com";

String subject="This is email title";

String body="Hello World, this is my first email";

MailEngine.send(from, to, subject, body);

If you want to add attachment to your email, or you want to add Cc, or send email in html format, you can use more complex send method from MailEngine class, such as

send( InternetAddress from, InternetAddress[] to, InternetAddress[] cc,
            InternetAddress[] bcc, String subject, String body,
            boolean htmlFormat, InternetAddress[] replyTo, String messageId,
            String inReplyTo, File[] attachments);

Done. Tested on Liferay 4.3.3