Liferay Book: Liferay Portal 5.2 Systems Development

Liferay Portal 5.2 Systems Development

A Java developer's guide to developing custom intranet systems, based on Liferay's platform. Sample Chapter; Code Download; Table of Contents;

Build Java-based custom intranet systems on top of Liferay portal

  • Learn to use Liferay tools to create your own applications as a Java developer, with hands-on examples
  • Customize Liferay portal using the JSR-286 portlet, extension environment, and Struts framework
  • Build your own Social Office with portlets, hooks, and themes and manage your own community
  • The only Liferay book aimed at Java developers
  • In More Detail

In Detail

Liferay portal is one of the most mature portal frameworks in the market, offering many key business benefits that involve personalization, customization, and workflow. If you are a Java developer who wants to build custom web sites and intranet applications using Liferay portal, this is where your search ends.

This book shows how Java developers can use Liferay as a framework to develop custom intranet systems, based on Liferay portal platform thus helping you to maximize your productivity gains. Get ready for a rich, friendly, intuitive and collaborative end-user experience!

The author's experience customizing Liferay using Java enables him to explain in a clear and precise manner how to build custom systems on top of Liferay portal.

Using this book you can customize Liferay into a single point of access to all an organization's data, content, web content, and other information from both existing in-house applications (HR, CRM) and external sources (such as Alfresco, FatWire, Magnolia, Vignette).

What you will learn from this book

This book will give you plenty of hands-on examples to customize and extend Liferay portal. You will learn how to:

  • Work with the JSR-286 portlets and Extension environment, helping you to build larger applications and reuse portlets in different scenarios
  • Build basic and advanced Struts portlets with permissions and a set of actions helping you to build enterprise-ready Java web applications
  • Manage communities and pages with locale and tracking features to employ layout templates dynamically
  • Customize WYSIWYG editor FCKEditor – Making images, links, videos, games, video queues, video lists, and play lists as part of web content
  • Empower CMS and WCM providing you with one central place to aggregate and manage all content
  • Build My Community – Share web sites, pages, and portlets with friends allowing you to introduce control panel and inter-portlet communication
  • Develop layout templates and themes in the Plugins SDK environment so that you can customize the overall look and feel of web sites and pages
  • Build your Social Office with portlets, hooks, and themes enabling you to be a part of the team without sacrificing your preferences
  • Stage, schedule, and publish web content with workflow capability allowing you to alter and manage what you have created
  • Build custom attributes, OpenSearch, Spring services, and web services thus helping you to build dynamic web sites smoothly

Approach

This book focuses on teaching by example. Every chapter provides an overview, and then dives right into hands-on examples so you can see and play with the solution in your own environment. All code samples run on both the latest Enterprise and Community releases.

Who this book is written for

This book will be most useful to professional Java developers who want to build custom web sites, portals, and highly customized intranet applications using Liferay portal as a framework.

This book is for Java developers, and you will get most from the book if you already work with Java but you need not have prior experience on Liferay portal. Although Liferay portal makes heavy use of open source frameworks such as Spring, Hibernate, Struts, and Lucene, no prior experience using these is assumed.

Acknowledgements

I would like to thank team members at Liferay, especially thanks to Raymond Auge, Brian Chan, Bryan Cheung, Jorge Ferrer, Michael Young, Jerry Niu, Ed Shin, Craig Kaneko, Brian Kim, Bruno Farache, Thiago Moreira, Amos Fong, Scott Lee and David Truong of Liferay for providing the valuable information and all the support. Thanks to friends in Liferay community for providing comments and suggestions.

Blogs
Does packt publishing provide beta versions of their books? I would love to order a pdf to get a look at the current edition even if it might have rough edges.
Hi Rob

Thank you.

I guess it is possible to get a PDF at http://www.packtpub.com/liferay-portal-5-2-systems-development/book. As expected, the book will be released at May 14, 2009.

Jonas Yuan
I purchase the ebook from the publisher. I was not allowed to download the book. I would really like to see what content is available. I can give you my order number and show you a receipt if there is a way to get the pdf now even if it isn't totally polished.
Hi John, Thank you!

I believe that only the publisher can answer the questions related to the release. As expected, the book will be released at May 14, 2009. Therefore, there are two more weeks - for downloading the ebook from the publisher, I guess.

Jonas Yuan
I've purchased the PDF version of the book but still can't download it. When is the expected release date?
Hi Tony,

Thank you! Just received message from the Publisher. It mentioned that the book "Liferay Portal 5.2 Systems Development" was scheduled to release on 30th May 2009.
Hi, I am planning to get this book but will it help me to develop portlets using netbeans? As in does it cover the portal plugin () and/or JSF bridge??
Regards
Hi Farouk,

You may find the table of content at http://www.packtpub.com/article/liferay-portal-5-2-systems-development-table-of-contents, and the sample chapter at http://www.packtpub.com/files/liferay-portal-5-2-systems-development-sample-chapter-5-managing-pages.pdf. Hope that it helps.

Thanks

Jonas Yuan
Downloaded the PDF to the book but am having an issue with the ext deploy not finding StrutsPortlet. Everything worked up till page 76. Below is the error
Any ideas?

Building jar: M:\liferay_portal\workspace\ext\ext-service\ext-service.jar
deploy:
[copy] Copying 1 file to M:\liferay_portal\apache-tomcat-6.0.18\lib\ext
compile:
[mkdir] Created dir: M:\liferay_portal\workspace\ext\ext-impl\classes
[javac] Compiling 10 source files to M:\liferay_portal\workspace\ext\ext-impl\classes
[javac] M:\liferay_portal\workspace\ext\ext-impl\src\com\ext\portlet\reports\ReportsPortlet.java:25: cannot find symbol
[javac] symbol : class StrutsPortlet
[javac] location: package com.liferay.portlet
[javac] import com.liferay.portlet.StrutsPortlet;
......etc.....
Hi John,

Thank you. The com.liferay.portlet.StrutsPortlet is a part of portal-impl.jar. You can find the source code at /portal/portal-impl/src in the IDE. After the ant targets - ant clean start build-ext, you would have this JAR ready in the EXT (/ext/modules/portal-impl.jar). And in /ext/.classpath (Navigator view), you should have

...
<classpathentry excluding="**/.svn/**|.svn/" kind="src" path="ext-impl/src"/>
<classpathentry excluding="**/.svn/**|.svn/" kind="src" path="ext-service/src"/>
...
<classpathentry kind="lib" path="modules/portal-impl.jar"/>
...
After trying a lot of things and redoing the deployment several times ( even switching to other branches), I found out what was wrong.

Page 75 says to copy build.${user.name}.properties to the ext project from the portal project, but this is what was causing the problems. The build.xml file in the ext project worked when I removed the build.${user.name}.properties. You may want to add a note or errata on the book web site. I think classpath.ext is the required attribute in ext's build.xml that disapears when the properties from portal is copied.
Hi John, Thank you. I will add a note on the book web site about this. Jonas Yuan
Hi Jonas - I have need to build a social space for a group of users comprising - a blog, a wiki, chat and alert. Will this book assist me in any way? Could it get to speed on how to extend the existing functionalities?

SPA
Hi Joy,

I believe that the chapter 10 - Building My Social Office - would give you answers, where you could see:

Develop the Social Office theme
Add mail and chat portlets
Build Social Office with portlets
Hook portal properties and custom JSP files (WIKI, blogs, forums, ducuments, etc. ) into Social Office
Use hooks more efficiently.

Hope that it helps.

Jonas Yuan
Hello Jonas

I just ordered your book (which is really good btw) and I'm reading the chapter 3 in the pdf version.
Is there a reason to recommend sysdeo tomcat plugin instead of WTP to deal with tomcat and debug mode?
I mean a reason due to some Liferay specificity?
Hi Amine,

Thank you so much. Sysdeo tomcat plugin in Eclipse IDE is used for demo purpose only, since it is small and simple. As mentioned in the book, You can use any other Tomcat plugins (for debug), such as WTP, MyEclipse, etc.

Good Luck!
Hi Joan,

Thanks for your response. I am trying to deploy ext and am getting the error below.

Compiling 10 source files to E:\projects\trunk\LIFERAY_PORTAL\workspace\ext\ext-impl\classes
E:\projects\trunk\LIFERAY_PORTAL\workspace\ext\ext-impl\src\com\ext\portlet\reports\ReportsPortlet.java:25: cannot find symbol
symbol : class StrutsPortlet
location: package com.liferay.portlet
import com.liferay.portlet.StrutsPortlet;
E:\projects\trunk\LIFERAY_PORTAL\workspace\ext\ext-impl\src\com\ext\portlet\reports\ReportsPortlet.java:40: cannot find symbol
symbol: class StrutsPortlet
public class ReportsPortlet extends StrutsPortlet {
E:\projects\trunk\LIFERAY_PORTAL\workspace\ext\ext-impl\src\com\ext\portlet\reports\action\ViewReportsAction.java:25: package com.liferay.portal.struts does not exist
import com.liferay.portal.struts.PortletAction;
E:\projects\trunk\LIFERAY_PORTAL\workspace\ext\ext-impl\src\com\ext\portlet\reports\action\ViewReportsAction.java:48: cannot find symbol
symbol: class PortletAction
public class ViewReportsAction extends PortletAction {

I am using netbeans 6.1 and a pluggable tomcat different from the one bundled with netbeans

cheers

SPA
problem solved by removing build.${user.name}.properties - thank you John Joseph Ryan for your post! SPA!
Hi SPA, thank you. I have added this as an errata on the book web site (page 75) - removing build.${user.name}.properties - this causes errors in Ext (especially, for NetBeans IDE) - Ant Target compile.
Hi Jonas,

using page 97 I tried to change the title of the jsp_portlet by adding javax.portlet.title.jsp_portlet=JSP Portlet to language.ext.properties under /ext/ext-impl/src/content folder and after cleanup and deploy of ext-web - the title remains the same tho the category now change to sample as expected. Any idea why the title refuses to change?

SPA
Hi SPA, thank you. You need to clean and deploy of the ext, too. If you change the JSP files only, you can do fast deploy of the ext-web. Hope that it helps.
Thanks it helps - pls could you guide me on how to import ext as a project in netbeans so I could access it in packages?

many thanks.

SPA
got the error below while compiling ViewBookReportsAction on page 103

found : javax.portlet.PortletPreferences
required: com.liferay.portal.model.PortletPreferences
PortletPreferences prefs = renderRequest.getPreferences();
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error

the errorneous line is
PortletPreferences prefs = renderRequest.getPreferences();

Pls guide towards correction and I am using latest source from the trunk.

thanks

SPA
Hi Jonas,

When running the servicebuilder in page 114/115 - the BookReportsEntry and BookReportsEntrysoap classes wwere not created thus am getting errors like cannot find symbol symbol : class ReportsEntry
location: class com.ext.portlet.bookreports.action.BookLocalServiceUtil
public static ReportsEntry addBook(ActionRequest req) throws PortalException, SystemException {

pls guide towards solution

SPA!
Hi SPA, Thank you. There is an erratum for the code in pages 114/115. The "ReportsEntry" should be "BookReportsEntry". The code from downloading web site is correct. I have added this as an erratum in the book web site. Thank you again.
Hi Jonas - the codes from the download work fine + gr8 work in the book.
Hi Jonas

On page 374 you have mentioned of a dock.vm template file that is present in this folder: /portal/portal-web/docroot/html/themes/_unstyled/templates/ - however, there is no dock.vm file in this folder. I am using the latest update 5.3.0.1 - am i missing something?

cheers

SPA
Hi SPA, thank you. The version 5.3 will update the dock (merging the dock.vm into portal_normal.vm) as #dockbar(). I will add this as an erratum in the book web site.
Hi Jonas - thanks for the update. Also, I have followed the instructions in the book on pages 377 - 378 on customizing the control panel by changing the theme and also by editing the edit page and view page. I even changed the company_logo.png in _diffs/images/common and also the custom.css in _diffs/css and after deploying all these using the build.xml of ext - nothing changes as the control panel remains the same - no change to look and feel and the logo too did not change.

Any guide?

SPA
Hi SPA, you should use 5.2.x, exactly compatible with the book. The version 5.3 is not released yet. So please use the 5.2.x. By the way, you can use 5.3 later and regenerate services.
Hi SPA, there are no exception in above code. You simply import javax.portlet.PortletPreferences ... Hope that it helps.
Hi SPA, you can try the following steps:

Importing the project into NetBeans 6.5
* Start the Import Eclipse Project dialog (via File -> Import Project menu)
In the Project Import dialog box, you are presented with two options:
* Import Projects from Workspace
* Import Project ignoring Project Dependencies
Choose the first option, and "browse" to the eclipse workspace where you have created the project

Hope that it helps.
Hello Jonas,

Your Chapter 3 gave me lots of answers about the dev environment.
But I still have a question.
When we checkout the portal module from Liferay svn repository, we can build an ext project dedicated to our custom needs.
Thus, this ext project can be shared among the development team through another svn repository.
But when we checkout the plugin sdk module at the end of chapter 3, it seems that we have to work directly in this checked out project
But custom plugins should not be stored in the svn liferay repository.
Is there a way, like in ext, to create our custom plugin sdk instance?
Or is it finally better to download directly the sdk in liferay sourceforge and customize it?

(btw i really liked your tip to fast dev plugins with tomcat emoticon )
Hi Amine, Thank you.

For the ext, we can build an ext project dedicated to our custom needs. This ext project can be shared among the development team through another svn repository.

For the Plugins SDK, we can do the same: custom plugins (themes, portlets, etc.) could be stored in the another svn repository. For example, we have plugin my-abc-portlet, we can store it in our repository: ../plugins/portlets/my-abc-portlet; then check out my-abc-portlet from our svn repository to the plugins SDK $PLUIGINS_SDK_HOME/portlets/.

Thus, this plugin project (for example my-abc-portlet) can be shared among the development team through another svn repository. :-)
I see
But in your exemple it seems you don't have a Plugins sdk coming from the Liferay repository, it's like you have a plugin SDK coming from sourceforge don't you?

In the Chapter 3, you first checkout the entire plugin SDK from Liferay SVN Repo into your workspace/Plugins SDK
Then you create plugins in there.

Then now if I want to store new portlets and themes in another repository I have two ways :
1. Cutting the link to the official Liferay repository and then posting this into my own svn repository
2. Or creating a copy of the plugin SDK (like we can do it with the EXT ant script in portal for exemple) that is not binded to the Liferay svn repo

Am I wrong?
Hi Amine, Thank you. You are right that I should add how to share project via another repository obviously.

In fact, as mentioned in the book, we can first check out entire repository in $PLUGINS_SDK_HOME from Liferay portal Plugins SVN; then check out custom portlet, such as abc-portlet, in $PLUGINS_SDK_HOME/portlets from another repository. Thus, we can get updates for sample portlets from Liferay portal SVN. At the same time, we can share custom portlets among the team. This would satisfy our different requirements.
Ok thank you Jonas !

I'm not used to work with two svn repositories in the same eclipse project that's why I didn't figure this out. :-)
Hi Amine, Thank you so much! It is possible to use only one repository, if you use Plugins SDK officially released version, such as 5.2.3.
Yes that is what I used to do.

I read step by step your chapter 4 and found issues with the jsp portlet (page 94)
I'm using the last portal version from svn (5.3).

When I try to add this hello world jsp portlet in my page, I get a null pointer exception and jsp portlet is not available in the "add application" div. (the entire category is missing)

The exception is coming from category_view.jsp when it tries to list available portlets.
It calls PortletConfigImpl.java and then null pointer occurs at line 202
bundle = portletBag.getResourceBundle(locale);

"portletBag" is null indeed (I can see it in debug mode with eclipse)

The line above is :
PortletBag portletBag = PortletBagPool.get(
_portlet.getRootPortletId());

So I suppose our new jsp portlet is not part of the portletBagPool as it returns null

What do you think about that? What could make a portlet out of the portletBag pool?
Note : I went back to the 5.2.3 version and got exactly the same issue
[resolved]
Actually it was not a problem of liferay versions.
The thing was that Liferay doesn't trim the portlet.getResourceBundleName() value.

As I inserted a tab and a carriage return in portlet.xml, Liferay could not figure out the name of the resource bundle for this jsp portlet and threw this exception (that crashes the Administration UI as well by the way...)
Hi Amine, Thank you so much.

Yes, we need to replace the following

<resource-bundle>
com.liferay.portlet.StrutsResourceBundle
</resource-bundle>

with

<resource-bundle>com.liferay.portlet.StrutsResourceBundle</resource-bundle>

in portlet(-ext).xml. You are right, Liferay portal doesn't trim the portlet.getResourceBundleName() value - this is a bug (see http://issues.liferay.com/browse/LPS-3829)
Trouble with book-street-theme in Chap. 6.
Jonas, thanks much for your great work on this book!

As I'm working my way through it I ran into a bit of confusion. In Chapter six "Preparing CSS styles in themes" on page 186-187 you refer to the book-street-theme folder, but I'm unable to find it.

Browsing ahead I see that we are creating this custom theme (book-street-theme) in Chapter nine.

Should I go ahead and finish Chap. 9 before continuing on Chap. 6 or would you suggest another approach to completing Chap. 6? I would not be surprised if I have missed an essential step prior to page 186, but I can't seem to find it. ;-)

Cheers!
Hi Sam, Thank you!

You are right that the entire theme (as a plugin) is available in chapter 9. In chapter 6, you can only find CSS files at /code/templates and styles/css/street and /code/templates and styles/css/workshop.

If you want to have a look on CSS files only, you may check these CSS files. If you want to see the entire theme and use it in run time, you may go ahead and finish the chapter 9.

You did not miss any steps. The book should provide the entire themes as plugins (street and workshop) in chapter 6, too.
Chapter4 -advanced struts portlet - [JDBCExceptionReporter:101] Duplicate entry error on tomcat startup

I was following your latest book, i am a newbie to liferay CMS. It was really a great book, After going through "advanced struts portlet" section of your book when i started tomcat it was giving the above error.
Somehow it got fixed. I don't know exact reason for that error. There was some space before & after fully qualified class name in portal-class for portlet element portal-ext.xml. Thinking might be this is the actual problem
Hi Nagendra, thank you so much!

You are right, Liferay portal doesn't trim the portal-class value - this is a bug (similar to the bug - http://issues.liferay.com/browse/LPS-3829). This issue got fixed in 5.3 like

<portlet-class> com.ext.portlet.reports.ReportsPortlet </portlet-class>

in portlet-ext.xml

Fortunately, it is working fine in 5.3 (At revision: 34353).
Chapter5: Managing Pages - [JDBCExceptionReporter:101] Unknown column 'extgroupim0_.creator' in 'field list'

I was getting above error when i followed as it is steps in book. I hope there is one extra column column 'creator' in service.xml for creator

I checked the same by downloading the code from http://www.packtpub.com/support for Liferay Portal 5.2 Systems Development
, In downloaded code 'creator' column is not there in service.xml of chapter5.

Please let me know which one to follow. Really book is of great use for newbies like me as well experienced programmers.
Hi Nagendra, Thank you so much! You did find a mismatching column of service.xml in the book.

If fact, the following line is not expected in page 145. It has "creator" in the book - It should be removed. Downloading code is correct (both service.xml and extgroup.sql).

<column name="creator" type="String" />

If you read sql in page 146, you will see that the query is correct, having no column "creator".

Thank you again, I will put above updates in website.