Liferay 6: querying webcontent dynamically

Liferay 6

Problem: we need to obtain webcontent items by custom query with conditions, one of them being webcontent item type for instance.

The JournalArticleLocalServiceUtil.dynamicQuery(DynamicQuery query) method seems to be just what we’re looking for.

Let’s make a custom query to get 100 latest webcontent items of types “blogs” and “news”. We also add condition on groupId, because we want only items from certain group:

DynamicQuery query = DynamicQueryFactoryUtil.forClass(JournalArticle.class, PortalClassLoaderUtil.getClassLoader())
.add(PropertyFactoryUtil.forName("type").in(new String[] {"blogs", "news"}))
query.setLimit(0, 100);

List <JournalArticles> = JournalArticleLocalServiceUtil.dynamicQuery(query);

It almost worked. Almost.
Continue reading


Liferay (6) practices

Working with Liferay always raises a lot of questions about best practices, or even just correct or even working ways to do things. That’s because Liferay is quite non-standard in many ways (which isn’t surprising actually, as really all Portlet containers invent their own tricks due to limitations of Portlets specificatin).

Today I’ll share some generic practices which I wish I myself knew when I was starting my Liferay experience.
Continue reading