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
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.
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(); %>