Liferay – for those of you who do not already know – is seemingly succesfull open source portal software written in java. It supports JSR-168 and JSR-286 portlets and has huge amount of features available straight from the box. And as it is open source software source code, bug database and development discussions are available to the general public.
Few books have been published about Liferay, but none of them really describe in detail how the portal engine and features work under the hood. I’ve read or have been reading following books:
– Liferay In Action ( Still work in progress, when finished could be the best current book about the subject! )
– Liferay Portal 5.2 Development
– Liferay Portal Enterprise Intranets & Liferay Portal 6 Enterprise Intranets
– Portlets in Action ( is about portlets, but has also fair deal about Liferay )
… and each one of them will teach you a bit or two about Liferay, how to do development and modify / extend features out of the box.
As with any project that has been live for sufficiently long, Liferay has numerous different patterns used in it’s code – but unfortunately how and why these patterns are used is not documented at all, or is documented poorly. Therefore learning to develop with Liferay requires one to dig deep and actually read the source.
Core component in Liferay development is ServiceBuilder, which is a code generation framework intended to be used to create entities and related service-stubs used to manage them. Developer writes service.xml from scratch or modifies existing service description and an utility creates entities, CRUD-dao and local/remote services.
As ServiceBuilder is used everywhere and services created with it contain no sensible javadocs, it is best for developers to forget what they were taught in school about java-development and start to learn ’Liferay patterns’. So forget javadocs, as api descriptions and method signatures are useless. Much better place to look at is service.xml for each entity and service and the actual code for the service.
Reading thorugh classes like JournalArticleLocalServiceImpl teach you a lot about how persistence is used.
It takes some time to realize that static utility classes are all the rage in the Liferay.
Classes like JournalArticleServiceUtil provide convenient access to services where-ever you might need them. You either like it or you don’t. You can easily have arguments for or against.
JournalArticleServiceImpl is an example of service level implementation, responsible mainly for permission checks and passing requests on to local service implementation, which does the actual work.
Configuration for services is done by Spring Framework and configuration is found in portal-impl -project’s src/META-INF directory. There you can find how and which classes get instantiated and what are the actual implementations for services.
At the view / controller level most of the functionality is bundled into a large Struts application. So understanding how Struts ( v.1 ) works is essential, when going through the source. Key places to start your journey:
– portal-web project’s web.xml and struts-config.xml
– MainServlet.java which is the main processing servlet
And when you need to shed a tear, take a look at the actual jsp views in portal-web project.
You will see lots of logic and service calls in views, which is a normal pattern once again in Liferay.
Going through the whole stack can be an interesting journey, but only then you really know what you are buying into.