Using portlet application name and portlet name to lookup a portlet

In the Generic method to get ObjectID from unique Name entry i talked about how you can find out ObjectID of a portlet/page or any other object from its unique name. BUt what if you want to find a portlet that does not have a uniuename assigned to it. In that case you can use combination of Portlet Application's uid and Portlet Name to find the portlet, you can use this method for that


private ObjectID getPortletObjectId(String portletAppId, String portletNameStr){
try {
InitialContext ctx = new InitialContext();
Name portletName = new CompositeName("portal:config/portletdefinition");
portletName.add(portletAppId ); //portal app Id
portletName.add(portletNameStr); //Portlet name
ObjectID portletDefOID = (ObjectID) ctx.lookup(portletName);
//ObjectID oidForUniqueName = (ObjectID) ctx.lookup(portletName);
return portletDefOID;
} catch (InvalidNameException e) {
e.printStackTrace(System.out);
} catch (NamingException e) {
e.printStackTrace(System.out);
}
return null;
}


This method takes portlet application id and the portletName to find out the portlet as argument and returns ObjectID. Now the question is what should be the value of the portlet object id and portlet name, you can find those values from the xmlaccess export of the portlet application


<web-app action="update" active="true" domain="rel"
objectid="1_VVILMKG100OPD0II63CET20000" removable="true" uid="PopupPortlet.war.webmod">
<url>file://localhost/$user_install_root$/PortalServer/deployed/archive/PopupPortlet.war.webmod/PopupPortlet.war</url>
<context-root>/wpcert/PA_Popup</context-root>
<display-name>PA_Popup</display-name>
<access-control externalized="false"
owner="uid=wasadmin,o=defaultwimfilebasedrealm" private="false"/>
<servlet action="update" active="true" domain="rel" name="PopupPortlet"
objectid="V_VVILMKG100OPD0II63CET20002" remote-cache-dynamic="false"/>
<portlet-app action="update" active="true" defaultlocale="en" domain="rel"
name="Application Name not available for this Application" objectid="2_VVILMKG100OPD0II63CET20004" uid="PopupPortlet.war" >
<access-control externalized="false" owner="uid=wasadmin,o=defaultwimfilebasedrealm" private="false"/>
<portlet action="update" active="true" defaultlocale="en" domain="rel"
name="PopupPortlet" objectid="3_VVILMKG100OPD0II63CET20006"
provided="false" servletref="V_VVILMKG100OPD0II63CET20002"
uniquename="com.webspherenotes.popup.portlet">
<access-control externalized="false"
owner="uid=wasadmin,o=defaultwimfilebasedrealm" private="false">
<role actionset="User" update="set">
<mapping subjectid="anonymous portal user"
subjecttype="user" update="set"/>
</role>
</access-control>
</portlet>
</portlet-app>
</web-app>



  • portletAppId: Value of uid attribute of portlet-app element

  • portletName: Value of name attribute of portlet element



I can use getPortletObjectId("PopupPortlet.war", "PopupPortlet"); to find out the ObjectID of the PopupPortlet

1 comment: