Posted on 3 Comments

Determine latest version of Web Content in Liferay

Liferay Logo

Most of the time when using Liferay’s Web Content (i.e. JournalArticle) you will want to determine the latest version to be displayed to your users. The following code snippet shows a simple solution to do so:

List<JournalArticle> articles = JournalArticleLocalServiceUtil.getStructureArticles(GROUPID, STRUCTUREID);
ListIterator<JournalArticle> it = articles.listIterator();
List<String> checkedArticleIds = new ArrayList<String>();

while (it.hasNext()) {
  JournalArticle article =;

  if (checkedArticleIds.contains(article.getArticleId())) {
    continue; // previous article version already checked

  JournalArticle articleLastVersion = JournalArticleLocalServiceUtil.getLatestArticle(GROUPID, article.getArticleId());


  System.out.println("Added articleId " + article.getArticleId() + " with version " + article.getVersion());

3 thoughts on “Determine latest version of Web Content in Liferay

  1. IT was a really really great atricle, thank you!

  2. Very very good.

  3. But this is not optimised way to do this, what if we have tens of thousands of articles, you must offer a way to query database for latest article versions not to retrieve all articles and then select the latest IDs.

    thank you

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.