In Java, developers are used to being able to find lots of context information
at runtime. You can learn about what user is browsing your application, what
page it’s on, what site it’s in, and lots more. Wouldn’t it be great if you
It’s a part of the
Liferay global object that’s automatically available to you
in Liferay at runtime. You can refer to the object as
ThemeDisplay object provides information on many aspects of a portal.
It can identify the portal instance, the current user, the user’s language, and
the user’s navigational context. It can tell you the paths to a portlet’s
scripts and images, a theme’s images and files, and a portal’s main folder. And
it lets you know if a user is signed in and if the user is being impersonated.
You can quickly assess your portal surroundings with
This tutorial describes some of the most commonly used
for getting IDs, paths, and user sign-in details.
ThemeDisplay methods below, you can grab IDs of various portal
getCompanyId: Returns the company ID.
getLanguageId: Returns the user’s language ID.
getScopeGroupId: Returns the group ID of the current site.
getUserId: Returns the user’s ID.
getUserName: Returns the user’s name.
Now that you know how to retrieve IDs of some of Liferay’s key elements, you can learn how to get paths to various deployed entities in the portal.
ThemeDisplay object has methods for retrieving commonly used file paths.
Below are a few of the methods:
getPathImage: Returns the relative path of the portlet’s image directory.
getPathMain: Returns the path of the portal instance’s main directory.
getPathThemeImages: Returns the path of the current theme’s image directory.
getPathThemeRoot: Returns the relative path of the current theme’s root directory.
Now that you know how to retrieve paths to Liferay’s deployed entities, you can next learn how to get information about the current user.
Here are a couple methods related to the current user.
true if the current user is being impersonated.
Authorized administrative users can
act as another user to test that user’s account.
true if the user is logged in to the portal.
alert('Hello ' + Liferay.ThemeDisplay.getUserName() + '. Welcome Back.')
The example above alerts a signed in user with a personalized greeting.
Otherwise, it defaults to a guest greeting. Although this is a basic example, it
shows how you can easily define unique user experiences with the