ACA Blog

ACA Blog

June 2020
« May    


Liferay – The Missing Parts: web content article priority

Dorien JorissenDorien Jorissen

When working with the web content management part of Liferay you quickly start using the Asset Publisher because of its versatility. This portlet enables you to gather and present different kinds of content in a multitude of ways. It can gather content in a dynamic way, by means of a search in a certain scope, on one or more asset type, filtering on tags/categories, or manually, where you select a fixed set of content items yourself.

When selecting content dynamically you’re able to define how the results will be sorted depending on certain fields and when selecting manually you define the order yourself. What you will quickly discover however is that sometimes you need something in between: you want to do a dynamic selection, but have a more specify way to define the order. The easiest way would be to use an already existing field where you could enter some sort of number, a weight, that will define how content needs to be sorted. When looking at the Asset Publisher configuration it seems that there is already something for that: a field with the name priority. Only when you try to use this, you’ll notice that there is no way, except directly in the database, to fill in the priority on a web content article.


This blog post will show how you can easily provide a way to fill in this field so that it can be used in the Asset Publisher to get articles sorted in the way we want. A simple hook can be used to add this missing functionality to Liferay. In this hook we’ll need to 2 of the most used Liferay extension mechanisms, JSP overrides & service overrides, to reach our goal. The JSP override consists of two parts: one adds a priority menu item to the list of actions you see on the right of an article when editing it:

and the other is a small JSPs that is used to show the actual priority input field that can be filled in by the user (that also has some validation as the priority is supposed to be a positive double).

Once these JSPs are in place we also need to override Liferay’s JournalArticleLocalService so that we can actually store the priority value once the user has filled it in. This means providing an implementation that extends fromJournalArticleLocalServiceWrapper (some method parameters have been replaced by … in the code below for readability reasons):

and reference it in the liferay-hook.xml together with the location of the overridden JSP

You can see the service is pretty simple and just takes the article that was just created/edited, finds the corresponding AssetEntry and sets the priority that was extracted from the ServiceContext on it. In a similar way, by using an overridden JSP/service combination, you could also add something similar to documents (or any other Liferay object that has a linked AssetEntry). When deploying this hook you now have the option to fill in a priority on an article when creating or editing it by going to the Priority menu on the right hand side of the screen and filling in the input field. When you now configure the Asset Publisher to use this value for sorting you will actually get the behavior you would expect of the portlet in the first place (without customisation that is).


The code for this post can be found on GitHub: priority-hook

Interested in joining our team?

Interested in meeting one of our team members? Interested in joining our team?
We are always looking for new motivated professionals to join the ACA team!
Have a look at our new ACA job website: