Problem
Liferay gives lots of user settings. Here we provide a solution for removing or hiding unnecessary settings.
Solution
We want to customize it better to remove the unnecessary settings from the user setting navigation.
Benefits
- The Liferay default user setting with some user settings and customize it according to user need.
Prerequisites
- Java
- Liferay portal 7.2 +
- Basic knowledge of Liferay
Environment Requirements
- JDK 11
- Eclipse/Liferay Dev Studio
- Liferay Portal
Create a Liferay fragment module using the following steps.
- Go to Liferay workspace project → modules → new
- Select other → Liferay → Liferay Module Project Fragment
- Enter the project name.
![Navigate to Liferay workspace project | Liferay User setting navigation override Navigate to Liferay workspace project](https://www.ignek.com/wp-content/uploads/2024/03/Navigate-to-Liferay-workspace-project.webp)
- If you don’t have configured the server follow the following steps:
- Go to the “windows” setting on the eclipse navigation bar
- Select the “show view” -> “other”.
- Search servers
![Configure server in Eclipse for deployment | Liferay User setting navigation override Configure server in Eclipse for deployment](https://www.ignek.com/wp-content/uploads/2024/03/Configure-server-in-Eclipse-for-deployment.webp)
- Now open the “Servers”.
- Create a new server.
![Open Servers and creating new server | Liferay User setting navigation override Open Servers and creating new server](https://www.ignek.com/wp-content/uploads/2024/03/Open-Servers-and-creating-new-server-1024x583.webp)
- Select the Liferay server configuration from the menu and press “next”.
![Choose Liferay server config | Liferay User setting navigation override Choose Liferay server config](https://www.ignek.com/wp-content/uploads/2024/03/Choose-Liferay-server-config.webp)
- Browse your Liferay in your local and select the Liferay.
![Explore Liferay and choose your local option | Liferay User setting navigation override Explore Liferay and choose your local option](https://www.ignek.com/wp-content/uploads/2024/03/Explore-Liferay-and-choose-your-local-option.webp)
- Press “next” and after that press “finish”.
- The Liferay server has been configured and started.
- Click on “Next”. And select the following Icon. to browse.
![Adding host OSGi bundle | Liferay User setting navigation override Adding host OSGi bundle](https://www.ignek.com/wp-content/uploads/2024/03/Adding-host-OSGi-bundle.webp)
- the “com.liferay.users.admin.web” jar file of user-admin-web.select the jar.
![Selecting host OSGi bundle jar file | Liferay User setting navigation override Selecting host OSGi bundle jar file](https://www.ignek.com/wp-content/uploads/2024/03/Selecting-host-OSGi-bundle-jar-file.webp)
- Select the “Add File From OSGI”.
![Selecting override file from liferay icon | Liferay User setting navigation override Selecting override file from liferay icon](https://www.ignek.com/wp-content/uploads/2024/03/Selecting-override-file-from-liferay-icon.webp)
- Select the following files.
- edit_user.jsp:-
- This file resides in the path “META-INF/resources/edit_user.jsp”.
- edit_user.jsp:-
![List of available ODGi bundle to override | Liferay User setting navigation override List of available ODGi bundle to override](https://www.ignek.com/wp-content/uploads/2024/03/List-of-available-ODGi-bundle-to-override.webp)
- Click on “finish”. Finally, a fragment module has been created.
- Now, We have to update the “edit_user.jsp” file.
- we have to add an if statement to only add a custom screen navigator id if the portlet id is equal to my account portlet id. Luckily this is easy to do since my account portlet id is set in the init.JSP
// Update formNavigatorId
/* Begin override of My Account */
//initialize to the real form navigator id.
String formNavigatorId =
UserScreenNavigationEntryConstants.SCREEN_NAVIGATION_KEY_USERS;
if (portletName.equals(myAccountPortletId)){
// include the special prefix
formNavigatorId = "my.account." + formNavigatorId;
}
/* End override of My Account */
- We have concat the “my.account” with the formNavigatorId. So We have to pass this updatedFormNavigatorId in <liferay-frontend:screen-navigation/>Key attribute.
// Update Liferay_Frontend_screen_navigation
- It should be look like following with the updated edit_user.jsp
- With the help of updatedFormNavigatorId. The Liferay User Navigation Setting Will be hidden and We will get a blank screen if We access the user setting.
- So, We have to override the Liferay User navigation taglib to show specific user settings.
- There were two most important factors of liferay-frontend:screen-navigation which are following.
- ScreenNavigationCategory
- This category will be responsible for the top-level navigation.
- ScreenNavigationCategory
![Admin account details screen | Liferay User setting navigation override Admin account details screen](https://www.ignek.com/wp-content/uploads/2024/03/Admin-account-details-screen.webp)
- ScreenNavigationEntry
- This Entry will be responsible for the left-side navigation.
- ScreenNavigationEntry
![Exploring all features of admin account | Liferay User setting navigation override Admin account details screen](https://www.ignek.com/wp-content/uploads/2024/03/Exploring-all-features-of-admin-account.webp)
- We have to take The navigation category and the navigation entry taglib classes from the source code that we have to show on the page.
- For example:-
- We want to show information and the password in the left navigation on user settings under the “general” category navigation.
- Then We want the following classes from the taglib from the source code of Liferay. From the following path.
The blog follows the Liferay dxp 7.4.13.u24.
- Then We want the following classes from the taglib from the source code of Liferay. From the following path.
/liferay-dxp-src-7.4.13.u24/modules/apps/users-admin/users-admin-web/src/main/java/com/liferay/users/admin/web/internal/frontend/taglib/servlet/taglib
- The classes are as follows.
- For the Category navigation.
- UserGeneralScreenNavigationCategory
- For the Category navigation.
- The classes are as follows.
- For the Entry navigation
- BaseUserScreenNavigationEntry
- UserDisplaySettingsScreenNavigationEntry
- UserInformationScreenNavigationEntry
- UserPasswordScreenNavigationEntry
- For the Entry navigation
- Now, create a Mvc Portlet.
- Remove the portlet class and resource folder from the portlet.
- Create a constant named “ACCOUNT_PREFIX”. And assign value “”.that we have used in the “edit_user.jsp”. While updating the form navigator.
- Now add the following respective gradle/Maven dependency.
// Required Dependency
compileOnly group: 'com.liferay',name:'com.liferay.users.admin.web'
- This dependency will include all the dependencies related to the User-admin-web.
- Now create two packages
- com.liferay.user.setting.taglib.override.category
- com.liferay.user.setting.taglib.override.entry
- This package contains the files following.
- Category :-
- This package contains the classes that will show the categories on the liferay frontend navigation (Top most navigation).
- As per the example in the entry package we want the following classes that will be copied from the liferay source code.
- UserGeneralScreenNavigationCategory.
- We have to update the return value of the method “getScreenNavigationKey()”.
- Concat the ACCOUNT_PREFIX with SCREEN_NAVIGATION_KEY_USERS.
- UserGeneralScreenNavigationCategory.
// Update Screen_Navigation_Key
@Override
public String getScreenNavigationKey() {
return
LiferayUserSettingTaglibOverridePortletKeys.ACCOUNT_PREFIX +
UserScreenNavigationEntryConstants.SCREEN_NAVIGATION_KEY_USERS;
}
- Entry :-
- This package contains the classes that will show the entries on the liferay frontend navigation (left navigation).
- As per the example in the entry package we will add the following classes that will be copied from the liferay source code.
- BaseUserScreenNavigationEntry
- We have to update the return value of the method getScreenNavigationKey()”.
- Concat the ACCOUNT_PREFIX with SCREEN_NAVIGATION_KEY_USERS.
- BaseUserScreenNavigationEntry
- Entry :-
// Update Screen_Navigation_Key
@Override
public String getScreenNavigationKey() {
return
LiferayUserSettingTaglibOverridePortletKeys.ACCOUNT_PREFIX +
UserScreenNavigationEntryConstants.SCREEN_NAVIGATION_KEY_USERS;
}
- Now set the JSP renderer on the entry classes that you want to display on the user navigation setting some are following.
- UserDisplaySettingsScreenNavigationEntry
- UserInformationScreenNavigationEntry
- UserPasswordScreenNavigationEntry
- Now set the JSP renderer on the entry classes that you want to display on the user navigation setting some are following.
- We have to add the following set method of JSPRenderer in every entry class which redirects to the jsp page.
// Required Reference(JSPRenderer)
@Reference(unbind = "-")
public void setJSPRenderer(JSPRenderer jspRenderer) {
this.jspRenderer = jspRenderer;
}
Note:
- We have to set JSP renderer at every entry class method, Because we can’t set the JSP renderer the same as in the original implementation.
- Otherwise it will be null at runtime.
- Now deploy both modules to the liferay server and access the user setting.
- You will see there are only available settings that you have defined in the “liferay-user-setting-taglib-override” module.
![User display data of a user | Liferay User setting navigation override User display data of a user](https://www.ignek.com/wp-content/uploads/2024/03/User-display-data-of-a-user-1024x536.webp)