How to get Portlet Id using the portlet name in Liferay?

后端 未结 2 447
南笙
南笙 2021-01-11 22:51

I have a requirement of getting resource permission using portlet name.

I will have the name of the portlet not the Id.

Resource Permission name for a portle

相关标签:
2条回答
  • 2021-01-11 23:10

    If you look closely as to how the Portlet Id is generated based on the Portlet Name, you would get the answer.

    It is a constant pattern which is followed, so you can construct the Portlet Id like liferay does it if you have the name. Liferay also constructs the ID with the help of the portlet name.

    Pattern of portlet-id: <portletname in xml>_WAR_<servlet context name i.e. the war file without any special characters such as the hyphen>

    For example: If your portlet name is MyWork defined in portlet.xml and the generated file in the webapps folder (if you are using tomcat) is MyWork-portlet then the resultant Id will be MyWork_WAR_MyWorkportlet.

    Now if you have liferay source code, you can look at PortletLocalServiceImpl's private _readPortletXML method.

    Edit:
    If you want to find the portlets on a particular page (given the friendly-url of the page) then you may find this answer helpful.

    0 讨论(0)
  • 2021-01-11 23:18

    You can try this:

    System.out.println("ID : " + themeDisplay.getPortletDisplay().getId());
    
    System.out.println("InstanceID: " + themeDisplay.getPortletDisplay().getInstanceId());
    
    System.out.println("Portlet Name: " + themeDisplay.getPortletDisplay().getPortletName());
    

    Don't forget:

    <% ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
        themeDisplay.getUser().getScreenName(); %>
    
    0 讨论(0)
提交回复
热议问题