Liferay Portal isn’t a new technology – if it was a person, it could already drink beer and drive a car – but thanks to constant development and improvement by its creators, it still remains relevant in 2023. It can help you deliver your application quite a bit faster, and in this Liferay tutorial we’ll show how. Here are six features Java developers can use to boost your time to market.
Most projects start with a specific business concept, and it wasn’t any different in our case. We needed to develop a system that would allow the client’s employees to display and manage various content (blog posts, newsletters, information about contests etc.). We also needed to create a user hierarchy structure that would reflect the company’s organization, on the basis of which permissions would be granted for the specific parts of the aforementioned content. Of course, every user would also be required to log in to their account, and the administrator had to have the ability to manage the users, content, and permissions.
The software also had to be integrated with external systems and, last but not least, we needed to pay attention to the general look and feel of the portal, as it would be available for a big audience.
While we could create this system in Java using the Spring framework, like in other projects that we developed, some of the business requirements seemed quite familiar. We thought they could be implemented faster – or even were available out-of-the-box – if we consider using the Liferay technology.
What is Liferay?
Liferay is a free (although there is also a paid, enterprise version), open-source tool that allows you to efficiently and quickly deliver a specific system. Liferay (also known as Liferay Portal) was written and developed in Java. It’s a highly configurable (through the administration panel) technology, with an intuitive, easy-to-use interface. It offers many built-in Liferay portlet types that you can adapt to your project by using the admin configuration. It also has many management-related functionalities – you can manage users, organizations, and permissions, or log in as a different person thanks to the user impersonation function.
In the case of more complex business tasks, Liferay also allows Java developers to override the existing widgets and create their own – for example, the Liferay MVC Portlet (Model-View-Controller) that we constantly used in the project. In addition, the technology provides a Rest Builder to create REST API Interfaces, and a Service Builder to create database entities, services, and models (more about that below).
Another important aspect – especially in the case of systems that will be available for a wide audience – is the look and feel. Liferay Themes allow you to customize your website with a combination of CSS, JavaScript, HTML, and FreeMarker templates. It’s also possible to create your own theme using the provided tools.
There are many additional tools available for Java developers. For example, if you want to deploy a web app as a Liferay JSF portlet, there’s a bridge for that. If you’re interested in a Liferay Eclipse plugin, there’s a good chance you’ll find it in the Liferay IDE collection created by the technology’s developers and hosted on GitHub. There’s also an extensive Liferay plugin marketplace that’s full of interesting things, and a Liferay plugin project wizard (or portlet project wizard). Long story short, it’s a pretty powerful and flexible solution that might find use in various circumstances.
Liferay development – 6 important functionalities you can implement
Here are six functionalities you can implement faster thanks to Liferay. By doing that, you can accelerate the system’s development and therefore improve the time to market.
System login
The ability to log in to the system is one of the basic functionalities that we had to implement. You can use a ready-made Liferay portlet that allows users to log in to the portal by means of authentication based on an identifier, such as a username or an e-mail address (depending on the configuration).
Additionally, the portlet allows you to change the user’s password and recover or reset it, in case it was lost/forgotten. The users can access specific resources only after they log in to the portal. Thanks to this Liferay portlet, developers were able to quickly implement log-in functionality.
Liferay also provides the ability to import and export users to LDAP directories and a single-sign-on (SSO) configuration.
If you want to improve security, it’s also possible to change password policies with the use of the admin panel. There are several options:
- Password change – Allow or disallow the user to change their password,
- Syntax Checking – for example, change how long and how many special characters password should have,
- Password Expiration Time – define how long password should be valid,
- Lockout – user can try to log in a certain number of times before their account is blocked
You can assign specific password policies to specific users and whole user groups.
Organizations, roles and permissions
Our next task was to model the organizational structure of our client’s company. Liferay allows you to structure user groups to reflect the organization. In addition, it is possible to manage them – you can add/remove users, create roles for them, and grant them permissions. You’ve got three types of role to use: Normal, Site, and Organization.
Widgets and applications
Liferay also allows for the use of widgets/portlets which are web apps that return data and generate responses with specific content to be displayed on the system page. Widgets can be managed and placed on a page with the use of the admin panel. The cool thing about that is that you don’t need to worry about the arrangement of other elements on the page – it’s handled by the Liferay application. Permissions of the portlet can also be managed by the administrator. In our project we used the widget and applications mentioned below, with a bit of custom coding to adapt them for the client’s specific business needs:
- Asset Publisher
Liferay provides the ability to add many types of resources, such as articles and documents. In most circumstances, you’ll want to present these resources to the end-user. This is where the Asset Publisher tool comes in handy. It is a highly customizable application that allows you to search for different types of content on the fly, giving you the ability to control what and how is displayed in a given place. This helps you create a more dynamic website.
You can search for resources in a variety of ways. You can set the resource selection to either dynamic or manual. With the dynamic setting, the content is displayed automatically, based on the specified rules or filters. For example, you can set the Asset Publisher to display only resources of a certain type, or resources that have specific tags or categories applied to them.
When you select resources manually, the Asset Publisher only displays resources that have been explicitly chosen by the administrator. You can also configure how the content is displayed by creating new Application Display Templates which allow portal administrators to override the default settings, removing restrictions on how content is displayed in your application.
- Calendar widget
A standard calendar (as seen on the screen below) that shows events for individual users and sites and allows you to manage them. It’s divided into sections dedicated to the user and the site itself. You can also customize new calendars, add events and change email notification settings.
- Forms app
A module you can use to build your own forms that can be widely configured. For example, you can add field types: Text Field, Single Selection, Multiple Selection, Date, Grid, etc. Such forms are one of the most often used elements in applications. Users can use them to input data (eg. names or dates of birth) and make various choices in the system.
MVC Portlet
Sometimes the client’s requirements are more complicated. For example, if you need to display data from a database (or any API), add or modify it – the MVC Portlet is the perfect solution. It’s based on the well-known Model-View-Controller architecture, which is designed to separate each layer of the module’s operation. With it, you can create modules that you will be able to place anywhere in your system using the “drag & drop” functionality. The generated template is configured by default, and ready to be used.
Adding such a portlet requires a few simple steps:
- Generate the MVC Portlet module template
- Deploy it by running the blade deploy command
- Place the portlet on the selected page using the “drag & drop” functionality (just use the mouse, and move it wherever you want it)
As you can see, the template for a working portlet is very easy to obtain. From that moment on, it’s available on the website, and you can start implementing your own business logic.
Service Builder
Service Builder is one of the largest and most frequently used tools for creating new database entities. It uses relational-object mapping, which generates subsequent layers on the basis of a single .xml file:
- model – in which classes corresponding to the created entity are generated
- persistence – downloading and saving data to the database
- service – a clean layer, ready to implement the interface and business logic
After generating the basic service builder, we get two modules – API and service. This configuration file is in the service module under the name service.xml, and in its default version it looks like this:
Now let’s describe what it consists of and what functionalities it has:
- Namespace tag – a unique namespace attached to the name of an entity in the database (protects against conflicts caused by duplicate names)
- Entity tag – it contains information about the name of the given entity
- Column tags – defines columns and the types of their values that will be stored in the database
- Order – the order in which records are stored in the database
- Finder – functionality that allows you to search for data using specific parameters (like objects after the field named “field2” – in the example above).
To build entities and generate classes needed to implement the logic, execute the command blade gw buildService. After this, you should have the following module structure:
From now on, you can define the behavior of servers related to this entity in the “FooLocalServiceImp” class. After rebuilding the module, you can use these methods.
REST Builder
REST Builder is a powerful tool that consistently generates the code needed to implement and configure the appropriate endpoints (based on the OpenAPI profile) so that they are ready for consumption.
The main advantage of this module is the speed of the REST service development. The programmer does not have to worry about the appropriate endpoint configuration, annotations, permissions. The code is automatically generated, and everything’s ready to implement the business logic.
This service enables an easy-to-configure ability to use pagination, filtering, or search by declaring the appropriate values in OpenAPI.
Responses are returned in both JSON and XML formats. The end-user can decide in which format he wants to read the answer.
First, you need to build a new module. The process is similar to the previous modules, but in this case, you’ll need to select “rest-builder” from the context menu. This way, two modules – API and IMPL – should be generated. In the latter, you’ll find the rest-openapi.yaml file, which will be the source of your API. We fill it in based on the OpenAPI specification. For example, the file might look like this:
All OpenAPI profiles contain three sections: info, components, and paths. The first one (“info”) contains information about the OpenAPI version, our API version, and the title. The “components” section contains schemas/entities that can be returned or consumed by the API. In this case, an entity named simply “Entity” is created, which contains the fields “name” as a string and “id” as a number. The last section, “paths”, defines the name and structure of the endpoint. In this case, the “entityId” parameter is passed to the GET “/entities” endpoint, and the “Entity” object created in the previous section is returned as a response.
After executing the blade gw buildRest command, resources and POJOs of your schemas and JAX-RS application will be generated. After verifying correctness, run the blade deploy command. That’s it, the endpoint is ready to be consumed. 😊
Summary
Liferay is a pretty old tool – it was created at the turn of the century, in the year 2000. Because of this, as a CTO you might be tempted to forgo it in favour of newer solutions. However, this is not a choice that should be made lightly, because Liferay is still being developed by its authors, and has a lot to offer – both in terms of practical, business uses, and suprisingly powerful customization options.
It’s a bit hard to start learning this technology, but it has many functionalities that can be used in modern systems. In this article, we’ve only shown you a small part of the possible options, but it should be enough to see how this solution can help you accelerate the development of your application, and whether Liferay training is something worth considering.
Are you in need of powerful software?
No matter how good your time to market is, sometimes it just won’t be good enough. In such circumstances outsourcing your project to a dedicated, outside vendor might be a better solution. Want to create some great custom software based on Liferay? Our experts can help you. Write to us at hello@pretius.com and tell us your needs. We’ll get back to you in 48 hours.
Liferay tutorial FAQ
Here are answers to some common questions regarding Liferay.
Where can I download Liferay?
You can find the Liferay Community Edition here.
How to add and select Liferay project?
You can add MVC liferay plugin portlets by going to “File”, “New”, and “Liferay Plugin Project”.
Is there a slim Liferay runtime?
Yes, you can find the information about it here.
How to install a new Liferay server?
Go to “Servers”, “New” and “Server”. More information here.
What is Liferay DXP?
The commercial variant of the technology is currently marketed as a comprehensive Liferay DXP platform. The newest version is Liferay 7.
What is on a Liferay dashboard?
Liferay has a Content Dashboard that offers access to various options, including content lists and an audit tool.
What is a Liferay workspace?
A Liferay workspace is an environment that contains your Liferay projects.