I am writing a JSR-168 portlet that can be added to a container multiple times. Each container (Liferay, JBoss, etc.) has its own internal way of differentiating between multiple instantiations of the same portlet.
I, however, would like to uniquely identify my portlet instance inside the doView() method itself.
Is there any standard, JSR-168 mechanism to retrieve some unique identifier that’s different for each instance of my portlet? I’ve seen various solutions where people randomly generate unique IDs and save them in the session, but I’d prefer a standard mechanism if one exists.
Portlet 1.0 (168) provides the RenderResponse.getNamespace() method, which should be unique per portlet instance.
From spec: PLT.12.3.4 Namespace encoding:
If you want to access it in processAction, you’ll probably want to store it in the session or as an actionURL parameter.
If upgrading is an option, Portlet 2.0 (286) changes the underlying PortletResponse interface to provide the getNamespace() method and also adds a PortletRequest.getWindowID() method which might be of some use to you.