Using a Custom Portlet in Place of the User Personal Bar

In this article, you’ll learn how to write the single Java class required to replace the default User Personal Bar with a custom portlet. Writing the portlet itself is up to each developer’s needs. See the documentation on portlets if you need guidance.

  1. Create an OSGi module.

  2. Create a unique package name in the module’s src directory and create a new Java class in that package.

  3. Above the class declaration, insert the following annotation:

    @Component(
        immediate = true,
        property = {
            "model.class.name=" + PortalUserPersonalBarApplicationType.UserPersonalBar.CLASS_NAME,
            "service.ranking:Integer=10"
        },
        service = ViewPortletProvider.class
    )
    

    The model.class.name property must be set to the class name of the entity type you want the portlet to handle. In this case, you want your portlet to be provided based on whether it can be displayed in the User Personal Bar.

    You may recall from the Portlet Providers articles that you can request portlets in several different ways (e.g., Edit, Browse, etc.).

    You should also specify the service rank for your new portlet so it overrides the default. Make sure to set the service.ranking:Integer property to a number that is ranked higher than the portlet being used by default.

    Since you want to display your portlet instead of the User Personal Bar, the service element should be ViewPortletProvider.class.

  4. Update the class’s declaration to extend the BasePortletProvider abstract class and implement ViewPortletProvider:

    public class ExampleViewPortletProvider extends BasePortletProvider implements ViewPortletProvider {
    
    }
    
  5. Specify the portlet you want in the User Personal Bar by declaring the following method in your class:

    @Override
    public String getPortletName() {
        return PORTLET_NAME;
    }
    

    Replace the PORTLET_NAME text with the portlet to provide when one is requested by the theme template. For example, the default portlet uses com_liferay_product_navigation_user_personal_bar_web_portlet_ProductNavigationPersonalBarPortlet

If you want to inspect the entire module used for Liferay’s User Personal Bar, see the product-navigation-user-personal-bar-web module.

« Customizing the User Personal Bar and MenuCustomizing the Personal Menu »
この記事は役に立ちましたか?
0人中0人がこの記事が役に立ったと言っています