|
Home > Archive > WebSphere Portal Server > July 2006 > Can a portlet find the ID of the page it is on
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Can a portlet find the ID of the page it is on
|
|
| Raymond Khalife 2006-04-02, 8:03 pm |
| Hello,
I'm wondering if there is a way for a portlet to know which page it is on. Perhaps from it's context or something like this.
I want the same portlet to behave differently depending on the page it is on and I would like to avoid creating parametrized copies of the same portlet.
I saw a post with something like:
########################################
####################
Context ctx = new InitialContext();
Name pageName = new CompositeName("portal:uniquename");
// unique page name
pageName.add("uniquePageName");
ObjectID oid = (ObjectID) ctx.lookup(pageName);
########################################
####################
But i would like something to find the unique id, and not rely on the uniquename.
Regards,
Raymond.
| |
| Raymond Khalife 2006-04-02, 8:03 pm |
| By the way, I'm trying to do this in JSR 168.
Cheers,
Raymond
| |
| Raymond Khalife 2006-04-02, 8:03 pm |
| Found it for JSR-168:
########################################
###################
Context ctx;
String name = null;
PortletServiceHome psh = null;
boolean serviceAvailable = false;
try {
ctx = new InitialContext();
psh = (PortletServiceHome) ctx.lookup("portletservice/com.ibm.portal.portlet.service.model.NavigationSelectionModelProvider");
serviceAvailable = true;
} catch (javax.naming.NameNotFoundException e) {
} catch (NamingException e) {
}
if (serviceAvailable) {
NavigationSelectionModelProvider provider = (NavigationSelectionModelProvider) psh
. getPortletService(NavigationSelectionMod
elProvider.class);
try {
NavigationSelectionModel model = provider
.getNavigationSelectionModel(request, response);
ContentNode node = (ContentNode) model.getSelectedNode();
name = node.getObjectID().getUniqueName();
} catch (ModelException e1) {
}
}
########################################
###################################
Cheers,
Raymond
| |
|
| We have to track what page we are to track hit statistics, so I created some javascript that would find our page. As we load, we execute these scriptlets:
<SCRIPT LANGUAGE="JavaScript">WTcreatePortalPath("<wps:title locale='en'/>");</SCRIPT>
The wps:title tag is the same one used to create the navigation. When we get done, we have a comma deliniated string of where we are at: MyCaterpillar,Home,etc. To get the data into your app, you might have to use a hidden field on the page. Not sure
how that would work...
Notice that I always use the english one, becuase it will change with the language. This is an elegant way to do it because you can use the tag the portal provides. You might be able to get by with just using one of them.
good luck!
| |
|
| Just in case anyone wants to do this in the IBM API:
String pageName = null;
try {
PortletRequest request = (PortletRequest) getFacesExternalContext()
.getRequest();
ModelUtil util = ModelUtil.from(request);
NavigationNode node = (NavigationNode) util
.getNavigationSelectionModel().getSelectedNode();
pageName = node.getContentNode().getObjectID().getUniqueName();
} catch (ModelException e) {
}
Please remember that the PortletRequest and PortletResponse used here are from the org.apache.jetspeed.portlet package.
|
|
|
|
|