|
Home > Archive > WebSphere Portal Server > December 2007 > HowTo get page ID on Portal V6.0
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 |
HowTo get page ID on Portal V6.0
|
|
|
| Hi,<br />
<br />
In portlet JSR168, Portal v6.0. How can we get the UNIQUE_NAME of page that instance of the portlet is?<br />
<br />
We'v seen : <br />
<br />
ModelUtil util = ModelUtil.from(request);<br />
NavigationNode node = (NavigationNode)util.getNavigationSelectionModel().getSelectedNode();<br />
String pageID = node.getContentNode().getObjectID().getUniqueName();<br />
<br />
and :<br />
<br />
PortletParameters parameters = PortletParameters.getInstanceOrNull();<br />
String page = parameters.getParameter("pageLocation");<br />
<br />
However, these ways are to old IBM API and portal v5.0 v5.1.<br />
<br />
Thanks.
| |
| Jim Barnes 2007-12-10, 1:25 pm |
| public static ObjectID getCurrentPage(HttpServletRequest request, HttpServletResponse response) throws StateException, NamingException, IOException {<br />
ObjectID oId = null;<br />
final PortalStateManagerService service = getStateManager(request, response);<br />
final StateAccessorFactory stateFct = (StateAccessorFactory) service.getAccessorFactory(StateAccessorFactory.class); <br />
final StateAccessor stateAcc = stateFct.getStateAccessor(); <br />
final StateHolder state = stateAcc.getStateHolder(request); <br />
stateAcc.dispose(); <br />
<br />
final SelectionAccessorFactory selFct = (SelectionAccessorFactory) service. getAccessorFactory(SelectionAccessorFact
ory.class); <br />
final SelectionAccessor selAcc = selFct.getSelectionAccessor(state); <br />
oId = selAcc.getSelection(); <br />
<br />
return oId;<br />
}<br />
<br />
then from that oid you can get the uniquename, in a jsr 168 you can request the portletstatemanager service instead<br />
<br />
IBM Certified System Administrator -- WebSphere Portal V6.0, V5.1, V5.0<br />
IBM Certified Solution Developer -- WebSphere Portal V5.1, v6.0<br />
<br />
The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM
| |
|
| Thanks Jim,<br />
<br />
Just one more thing. This oid is the same stored in RELEASE DB? (unique_name) <br />
<br />
Thanks.
| |
| Jim Barnes 2007-12-10, 7:23 pm |
| Well the string representation of it is.<br />
The Object you get back is of type ObjectID and that does have the same string representation as what is stored in the db, along with it comes the unique name as stored in the release domain, if one exists. if no uniquename for that page is there it wi
ll return null.<br />
<br />
IBM Certified System Administrator -- WebSphere Portal V6.0, V5.1, V5.0<br />
IBM Certified Solution Developer -- WebSphere Portal V5.1, v6.0<br />
<br />
The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM
| |
| marcelotada@iberianet.com.br 2007-12-11, 1:25 pm |
| Im afraid I dont understand this code. <br />
<br />
This method goes inside the portlet right? Request and response doesnt should to be a PortletRequest and PortletResponse? How getStateManager(request) works? It uses a PortletServiceHome to get the service?<br />
<br />
I'm on faces portlet (JSR168) and Im not sure about the compatibility of all of this.<br />
<br />
Thanks.
| |
| Jim Barnes 2007-12-11, 1:25 pm |
| Well you could do this either way. You can use the portlet state manager or the portal statemanager<br />
<br />
The portlet state manager is retrieved this way<br />
private static PortletStateManager getPortletStateManager(PortletRequest request, PortletResponse response) throws StateException, NamingException {<br />
PortletStateManager mgr = null;<br />
if (psHome == null ){<br />
Context ctx = new InitialContext();<br />
psHome = (PortletServiceHome) ctx.lookup("portletservice/com.ibm.portal.state.service.PortletStateManagerService"); <br />
}<br />
try {<br />
PortletStateManagerService service = (PortletStateManagerService) psHome. getPortletService(PortletStateManagerSer
vice.class);<br />
mgr = service.getPortletStateManager(request, response);<br />
} catch (Exception ex) {<br />
System.out.println("the portlet service was unable to be retrieved");<br />
} <br />
// you need to request the state manager on a per-thread basis<br />
return mgr;<br />
}<br />
<p />
The portal statemanager is retrieved this way<br />
private static PortalStateManagerService getStateManager(HttpServletRequest request, HttpServletResponse response) throws StateException, NamingException {<br />
// you can cache the home interface<br />
PortalStateManagerService service = null;<br />
if(psmsHome == null) {<br />
Context ctx = new InitialContext();<br />
psmsHome = (PortalStateManagerServiceHome) ctx.lookup("portal:service/state/PortalStateManager");<br />
}<br />
try {<br />
service = psmsHome.getPortalStateManagerService(request, response);<br />
} catch (Exception ex) {<br />
System.out.println("the state manger service was unable to be retrieved");<br />
} <br />
<br />
// you need to request the state manager on a per-thread basis<br />
return service;<br />
}<br />
<p />
So how ever you want to retrieve the statemanager you can change the code above and pass in either the portlet request and response or the servletrquest and response.<br />
<br />
If you want to call the method in your portlet then you can change it to get the portletstatemanager and pass in the request objects, You can get the jsr request object <br />
<br />
if you are using rad 7 you can use the following<br />
RAD v7: com.ibm.faces.portlet.httpbridge.PortletRequestWrapper request = <br />
(PortletRequestWrapper)FacesContext.getCurrentInstance().getExternalContext().getRequest(); <br />
javax.portlet.PortletRequest prequest = request.getPortletRequest(); <br />
<br />
IBM Certified System Administrator -- WebSphere Portal V6.0, V5.1, V5.0<br />
IBM Certified Solution Developer -- WebSphere Portal V5.1, v6.0<br />
<br />
The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM
| |
| Jim Barnes 2007-12-11, 1:25 pm |
| I am including an example helper class<br />
<p />
IBM Certified System Administrator -- WebSphere Portal V6.0, V5.1, V5.0<br />
IBM Certified Solution Developer -- WebSphere Portal V5.1, v6.0<br />
<br />
The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM
| |
| marcelotada@iberianet.com.br 2007-12-12, 7:23 pm |
| Hello Jim, thank you very much for your help.<br />
<br />
Now Im in a problem to return the service on getPortletStateManager method, it is returning null. I have no idea about the cause of this. Do u?<br />
<br />
Thanks,<br />
Tada, Marcelo.
| |
| Jim Barnes 2007-12-12, 7:23 pm |
| could be that the request objects coming out of jsf are not correct, print them out and check<br />
<br />
IBM Certified System Administrator -- WebSphere Portal V6.0, V5.1, V5.0<br />
IBM Certified Solution Developer -- WebSphere Portal V5.1, v6.0<br />
<br />
The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM
| |
| marcelotada@iberianet.com.br 2007-12-12, 7:23 pm |
| Hi Jim,<br />
<br />
So, I think that request object its okay, however the stacktrace prints this message: java.lang.IllegalStateException: The internal portlet request cannot be found.<br />
<br />
This is how I get PortletRequest and PortletResponse: <br />
PortletRequest request = (PortletRequest) getFacesContext().getExternalContext().getRequest();<br />
and<br />
(PortletResponse) getFacesContext().getExternalContext().getResponse()<br />
<br />
PortletRequest is in JSR168 specs. <br />
<br />
Like I said, I have no idea about the cause of this null pointer exception.<br />
<br />
Thanks,<br />
<br />
Tada, Marcelo<br />
IBM Certified Solution Developer - Websphere Portal v6.0
| |
| Jim Barnes 2007-12-12, 7:23 pm |
| as rad 7 jars are the only supported jsf jars on portal 6<br />
<br />
you need to use the following to get the portlet request<br />
com.ibm.faces.portlet.httpbridge.PortletRequestWrapper request =<br />
(PortletRequestWrapper)FacesContext.getCurrentInstance().getExternalContext().getRequest();<br />
javax.portlet.PortletRequest prequest = request.getPortletRequest(); <br />
<br />
IBM Certified System Administrator -- WebSphere Portal V6.0, V5.1, V5.0<br />
IBM Certified Solution Developer -- WebSphere Portal V5.1, v6.0<br />
<br />
The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM
| |
| marcelotada@iberianet.com.br 2007-12-13, 1:26 pm |
| Hi Jim,<br />
<br />
I dont understand exatly the difference between these Requests. <br />
<br />
Besides, we keep on problem... Now, the service PortletStateManager doesnt recognize the Acessor type (SelectionAccessorFactory). The stackTrace shows an UnknowAcessorTypeException.<br />
<br />
Thanks,<br />
Tada, Marcelo.<br />
IBM Certified Solution Developer - Websphere Portal v6.0
| |
| Jim Barnes 2007-12-13, 1:26 pm |
| what version of 60 are you running this on?<br />
<br />
jim<br />
<p />
IBM Certified System Administrator -- WebSphere Portal V6.0, V5.1, V5.0<br />
IBM Certified Solution Developer -- WebSphere Portal V5.1, v6.0<br />
<br />
The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM
| |
| Jim Barnes 2007-12-13, 1:26 pm |
| nevermind I looked at this again, I was afraid of that, you really need the portal state manager service then, you can use this helper, and then cast those request objects to the httpservlet request and response to get the page id<br />
<br />
Now I know this one works I have used it with the httpservlet request<br />
<br />
IBM Certified System Administrator -- WebSphere Portal V6.0, V5.1, V5.0<br />
IBM Certified Solution Developer -- WebSphere Portal V5.1, v6.0<br />
<br />
The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM
| |
| marcelotada@iberianet.com.br 2007-12-20, 7:23 pm |
| Hi Jim!<br />
<br />
Thank you so much for your help. It Works! <img class="jive-emoticon" border="0" src="images/emoticons/happy.gif" alt=" "><br />
<br />
Now I've another problem. I'm trying to get the OID from page saved on DB. I have the UNIQUE_NAME then I execute a query that returns me its OID. The problem is that this OID is not a number when suposed shoulded be. The query returns a binary 18bytes. (l
ike a blob) <br />
<br />
This sounds really stranger to me. Have you any idea about this?<br />
<br />
Thanks,<br />
Tada, Marcelo.<br />
IBM Certified Solution Developer - Websphere Portal v6.0
| |
| Jim Barnes 2007-12-21, 7:37 am |
| yes it is returning an object, you can use the identification service to serialize that into a string.<br />
<br />
here is a helper for that<br />
<br />
you can do what you need to do like this<br />
IdentificationHelper.getStringForObjectID(yourObject);<br />
<br />
that will serialize it to a string for you.<br />
<p />
IBM Certified System Administrator -- WebSphere Portal V6.0, V5.1, V5.0<br />
IBM Certified Solution Developer -- WebSphere Portal V5.1, v6.0<br />
<br />
The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM
|
|
|
|
|