Foros de discusión

Get URL from wiki node ID

Jan Tošovský, modificado hace 12 años.

Get URL from wiki node ID

Liferay Master Mensajes: 565 Fecha de incorporación: 22/07/10 Mensajes recientes
Hello Everyone,

I am able to get a WIKI node ID using this way:
WikiNode node = (WikiNode) request.getAttribute("WIKI_NODE");
long nodeId = BeanParamUtil.getLong(node, request, "nodeId");

Is there any opposite way how to construct the URL in the form "http://myserver.com/web/home/pagename/-/wiki/Main/ from this ID?
The WIKI is scoped to that page.
I don't want to pass that complete URL as the parameter to my method, just that ID.

Regards,
Jan
thumbnail
Amos Fong, modificado hace 12 años.

RE: Get URL from wiki node ID

Liferay Legend Mensajes: 2047 Fecha de incorporación: 7/10/08 Mensajes recientes
Hi Jan,

You can create a portletURL like so (taken from top_links.jsp)

					<portlet:renderurl var="viewPageURL">
						<portlet:param name="struts_action" value="/wiki/view" />
						<portlet:param name="nodeName" value="<%= curNode.getName() %>" />
						<portlet:param name="title" value="<%= WikiPageConstants.FRONT_PAGE %>" />
					</portlet:renderurl>


It should also work if you change nodeName to nodeId. If you're not in a JSP, you should be able to use PortletURLFactoryUtil.create(..) to achieve the same thing.
Jan Tošovský, modificado hace 12 años.

RE: Get URL from wiki node ID

Liferay Master Mensajes: 565 Fecha de incorporación: 22/07/10 Mensajes recientes
Thanks, but using this JSP approach I am still getting not very user friendly form
http://mysite.com/sandbox?p_p_id=Tree_WAR_Treeportlet_INSTANCE_7cPy&amp;p_p_lifecycle=0&amp;p_p_state=maximized&amp;p_p_mode=view&amp;p_p_col_id=column-1&amp;p_p_col_pos=1&amp;p_p_col_count=2&amp;_Tree_WAR_Treeportlet_INSTANCE_7cPy_struts_action=%2Fwiki%2Fview&amp;_Tree_WAR_Treeportlet_INSTANCE_7cPy_nodeId=93413&amp;_Tree_WAR_Treeportlet_INSTANCE_7cPy_title=Title+Page

Is there any other option which needs to be set?
thumbnail
Fuad Efendi, modificado hace 11 años.

RE: Get URL from wiki node ID

Regular Member Mensajes: 180 Fecha de incorporación: 5/04/07 Mensajes recientes
Amos Fong:
Hi Jan,

You can create a portletURL like so (taken from top_links.jsp)

					<portlet:renderurl var="viewPageURL">
						<portlet:param name="struts_action" value="/wiki/view" />
						<portlet:param name="nodeName" value="<%= curNode.getName() %>" />
						<portlet:param name="title" value="<%= WikiPageConstants.FRONT_PAGE %>" />
					</portlet:renderurl>


It should also work if you change nodeName to nodeId. If you're not in a JSP, you should be able to use PortletURLFactoryUtil.create(..) to achieve the same thing.



I had similar issue and it never worked for me. Finally I was able to locate a problem: parameter value (such as article title) contained "." (dot) character. I tried to compare with WIKI (which doesn't use JSP Tag): I added child page called "ABC Inc." - the problem doen't happen with WIKI.

But it happens in exactly similar code... if I use "." (dot) in a parameter value.


P.S.
"dot"=="period"=="."


P.P.S.

See http://issues.liferay.com/browse/LPS-6105
something similar happens...
Also, WIKI overrides default mapper...
thumbnail
Hitesh Methani, modificado hace 12 años.

RE: Get URL from wiki node ID

Regular Member Mensajes: 171 Fecha de incorporación: 24/06/10 Mensajes recientes
Hi Jan,

For creating url of wiki from node Id you can refer the blog

http://hiteshmethani.blogspot.com/2011/06/creation-of-urls-for-entities-in.html.

Regards,
Hitesh Methani.
Jan Tošovský, modificado hace 12 años.

RE: Get URL from wiki node ID

Liferay Master Mensajes: 565 Fecha de incorporación: 22/07/10 Mensajes recientes
Hitesh Methani:
http://hiteshmethani.blogspot.com/2011/06/creation-of-urls-for-entities-in.html.

Thanks. I am still missing what is the 'plid' and what is the best approach to retrieve it.
I've already seen several methods. Yours is another one. But it is not very clear to me what shloud be instead of 'cablevision.community.name' in my case.
In the WIKI search code is the following variant:
		        plid = PortalUtil.getPlidFromPortletId(resultScopeGroupId, portletId);
				PortletURL portletURL = PortletURLFactoryUtil.create(request, portletId, plid, PortletRequest.RENDER_PHASE);								
				portletURL.setWindowState(WindowState.MAXIMIZED);
				portletURL.setPortletMode(PortletMode.VIEW);
thumbnail
Amos Fong, modificado hace 12 años.

RE: Get URL from wiki node ID

Liferay Legend Mensajes: 2047 Fecha de incorporación: 7/10/08 Mensajes recientes
The plid is the ID of the layout your wiki portlet is on. If it's the current page, then you can use themeDisplay.getPlid(). If it's on another page, you should get the layout first using LayoutLocalServiceUtil (this method is probably easiest, getFriendlyURLLayout()).

If you're still not getting the friendly URL you need, look at wiki-friendly-url-routes.xml. You probably need to set some more parameters.

This blog may be helpful to you:
http://www.liferay.com/web/connor.mckay/blog/-/blogs/5262286
Jan Tošovský, modificado hace 12 años.

RE: Get URL from wiki node ID

Liferay Master Mensajes: 565 Fecha de incorporación: 22/07/10 Mensajes recientes
Thanks a lot for this clarification!
So if I knew the target layout in every case (and also the corresponding plid) , I could get the layout url using this simple code
String friendlyUrl = LayoutLocalServiceUtil.getLayout(plid).getFriendlyURL();

But I still cannot find any connection of Wiki Node ID to that layout.
If all portlets on that page are listed, I am getting '36' for the WIki portlet.
I'd like to pass the NodeID and get the corresponding Layout (page) in which that page-scoped Wiki is placed.
thumbnail
Amos Fong, modificado hace 12 años.

RE: Get URL from wiki node ID (Respuesta)

Liferay Legend Mensajes: 2047 Fecha de incorporación: 7/10/08 Mensajes recientes
Ah ok I see what you're getting at. This class should be very helpful to you: FindPageAction.java

You can use this action directly if you want by getting the front page (Should be easy using WikiPageLocalServiceUtil) of your wiki node and doing this:
themeDisplay.getPathMain() + "/wiki/find_page?pageResourcePrimKey=" + _page.getResourcePrimKey();

or I believe the code in question you need is:

		WikiNode node = WikiNodeLocalServiceUtil.getNode(
			pageResource.getNodeId());

		plid = PortalUtil.getPlidFromPortletId(
			node.getGroupId(), PortletKeys.WIKI);
Jan Tošovský, modificado hace 12 años.

RE: Get URL from wiki node ID

Liferay Master Mensajes: 565 Fecha de incorporación: 22/07/10 Mensajes recientes
Thanks a lot. Finally I use the following code:
private static String getUrlFromNodeId(long nodeId) throws Exception {
   WikiNode node = WikiNodeLocalServiceUtil.getNode(nodeId);
   long plid = PortalUtil.getPlidFromPortletId(node.getGroupId(), PortletKeys.WIKI);
   Layout layout = LayoutLocalServiceUtil.getLayout(plid);
   return layout.getFriendlyURL();	
}