Obtaining the object ID for a page or portlet

There are several use cases when a portlet needs to obtain the object ID used to uniquely identify a portlet or a page. For example, the object ID of a page definition is required for a portlet to launch a dynamic instance of that page. You can use the lookup() method of the JNDI Context class to obtain the object ID for a portlet or a page, passing the unique name of the page or portlet. As an alternative for portlets, you can obtain the object ID by using JNDI lookup() and passing a combination of the portlet application ID and the portlet name.
• For JSR 168 compliant portlets, the portlet application ID is the value of the ID attribute of the element in the portlet.xml. However, this attribute is not required by the Java Portlet Specification. If the ID attribute is not set, the portlet WAR file name is used as the portlet application ID.
• For IBM portlets, the portlet application ID is the UID attribute of the element. This attribute is required.
The following example shows both ways to find an object ID.
// initialization
Context ctx = new InitialContext();

// portal:uniquename prefix is required for unique name lookup
Name uniqueName = new CompositeName("portal:uniquename");

// portal:config/ prefix required for portlet definition lookup
Name portletName = new CompositeName("portal:config/portletdefinition");

// the unique name assigned to the page is example.org.page

ObjectID oidForName = (ObjectID) ctx.lookup(uniqueName);

// appID and portletName have already been set programmatically

ObjectID portletDefOID = (ObjectID) ctx.lookup(portletName);
The Name used for the lookup() method is created from a CompositeName, which is prepopulated with the required portal prefixes enclosed in quotes. This technique is used to avoid having to escape special characters in the prefix.
0 Comments To ' Obtaining the object ID for a page or portlet '

Post a Comment