Uniquely identify a JSR-168 portlet instance

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 instances of the same portlet.

However, I would like to uniquely identify my portlet instance within the method itself doView()

.

Is there any standard JSR-168 mechanism for obtaining a unique identifier that is different for each instance of my portlet? I've seen various solutions where people randomly generate unique IDs and store them in the session, but I'd prefer the standard mechanism if it exists.

+1


source to share


3 answers


Portlet 1.0 (168) provides the RenderResponse.getNamespace () method , which must be unique for each portlet instance.

From the specification: PLT.12.3.4 Namespace encoding :

The getNamespace method must provide a portlet with a mechanism to ensure that the returned string is unique across the entire portal page. For example, the getNamespace method will return a unique string that can be prefixed with a JavaScript variable name within the content generated by the portlet, ensuring that it is unique throughout the page. The GetNamespace method should return the same value if called multiple times in a rendering request.



If you want to access it in processAction, you probably want to store it in a session or as an actionURL parameter.

If upgrade is an option, Portlet 2.0 (286) modifies the underlying PortletResponse interface to provide a getNamespace () method and also adds a PortletRequest.getWindowID () method that you might find useful.

+3


source


No, there is no common identifier for the instance. I have implemented portlet container myself, there is no instance id in public api. There is one reason in the container. A portlet session ( javax.portlet.PortletRequest#getPortletSession()

) is unique for one portlet (defined by tag in portlet.xml

) and one user ( javax.servlet.http.HttpSession

), which is not enough for you.

So imho the id is generated (can also be a simple (sync) counter in the portletl class) and stored in the portlet session is the only portable way. The portlet class itself is usually shared between instances, so it is java.lang.System#identityHashCode(Object x)

also useless.



Why do you need this?

0


source


I'm surprised that this unique id doesn't seem to exist according to Ame. The instance ID can be used to store all of the portlet settings in our own database rather than in a container. One of the reasons we need to keep this on our own is because the preferences provided by the container do not support region specific settings.

For example, one portlet instance may have different language preferences.

We are trying to use Liferay for our needs.

0


source







All Articles