Forums de discussion

Redirect to web content edit article page

renu jyothi, modifié il y a 6 années.

Redirect to web content edit article page

New Member Publications: 5 Date d'inscription: 17/02/17 Publications récentes
Hi there,

I have a requirement where, I display the articles based on a custom sortfield. Each row has article ID as a hyperlink and I need to redirect to the edit article page, on click on the article id..

I tried creating a PortletURL, but still not able to redirect to the required page..

Below is the code I tried:
themeDisplay = (ThemeDisplay)request.getAttribute (com.liferay.portal.kernel.util.WebKeys.THEME_DISPLAY);
Layout layout = themeDisplay.getLayout();
long plid = layout.getPlid() ;
String journalportletId = PortletKeys.JOURNAL;
PortletURL portletUrlCntrlPanel=PortalUtil.getControlPanelPortletURL(request, journalportletId, refererPlid, themeDisplay.getLifecycle());

portletURL.setParameter("struts_action", "/journal/edit_article");
portletUrlCntrlPanel.setParameter("p_p_id","15");
portletUrlCntrlPanel.setParameter("p_p_lifecycle",PortletRequest.ACTION_PHASE);
portletUrlCntrlPanel.setParameter("struts_action", "/journal/edit_article");

PortletURL redirectURL = PortalUtil.getControlPanelPortletURL(request, journalportletId, refererPlid, themeDisplay.getLifecycle());
redirectURL.setParameter("struts_action", "/journal/edit_article");
redirectURL.setParameter("folderId","0");
redirectURL.setParameter("articleId", "21385");
redirectURL.setParameter("groupId", groupId+"");
redirectURL.setParameter("status","0");
redirectURL.setParameter("folderId","0");
//redirectURL.setParameter("articleId", "21385");
redirectURL.setParameter("groupId", groupId+"");
redirectURL.setParameter("status","0");
portletUrlCntrlPanel.setParameter("redirect",redirectURL.toString());
portletUrlCntrlPanel.setPortletMode(PortletMode.VIEW);
portletUrlCntrlPanel.setWindowState(LiferayWindowState.POP_UP);

Then, I am using this url in the jsp as:

<liferay-ui:search-container-column-text
name="Title" href="<%=portletUrlCntrlPanel %>"
value="<%=article.getUrlTitle() %>" >

Please help me out. Thanks in advance
thumbnail
Andrew Jardine, modifié il y a 6 années.

RE: Redirect to web content edit article page

Liferay Legend Publications: 2416 Date d'inscription: 22/12/10 Publications récentes
The best example is always in Liferay's source. in the /html/portlet/journal_content/view.jsp you will find


<liferay-portlet:renderurl portletname="<%= PortletKeys.JOURNAL %>" var="editURL" windowstate="<%= WindowState.MAXIMIZED.toString() %>">
	<portlet:param name="struts_action" value="/journal/edit_article" />
	<portlet:param name="redirect" value="<%= currentURL %>" />
	<portlet:param name="groupId" value="<%= String.valueOf(article.getGroupId()) %>" />
	<portlet:param name="folderId" value="<%= String.valueOf(article.getFolderId()) %>" />
	<portlet:param name="articleId" value="<%= article.getArticleId() %>" />
	<portlet:param name="version" value="<%= String.valueOf(article.getVersion()) %>" />
</liferay-portlet:renderurl>


.. in particular, not that it is a RENDER url, not an ACTION url. Also, don't forget that the groupId for your site, is not the same as the groupId for the control panel. The Control Panel is it's own site in Liferay.
Heiko Ottenbacher, modifié il y a 6 années.

RE: Redirect to web content edit article page

New Member Publications: 20 Date d'inscription: 05/09/14 Publications récentes
Hello Everybody,

how does that work in Liferay 7 (DXP)? As the PortletKeys.JOURNAL seems to have been vanished there...

Thanks in advance!
thumbnail
Andrew Jardine, modifié il y a 6 années.

RE: Redirect to web content edit article page

Liferay Legend Publications: 2416 Date d'inscription: 22/12/10 Publications récentes
Hi Heiko,

Yep, the portlet ids are normally bundled with the modules. The web content is now it's own module so what you have to do is look up the class to get the key and then adjust your project accordingly. In the past the portlet keys were numeric -- so web content portlet for example was 56. In the world of 7+ the portlet ids have changed to be the fully qualified class name with underscores (_) in place of periods (.). So if you have a class

com.abc.my.package.action.MyAction

then the portlet id would most likely be / is recommended to be --

com_abc_my_package_action_MyAction

Now to find the class. If you have the portal source downloaded (I am looking at GA5) you will find /modules/apps/web-experience/journal is where all the WCM stuff is hiding. In there will be a sub-module called journal-content-web -- which is the portlet. The class you are looking for is com.liferay.journal.content.web.constants and it has the following --

package com.liferay.journal.content.web.constants;

/**
 * @author Eudaldo Alonso
 */
public class JournalContentPortletKeys {

	public static final String JOURNAL_CONTENT =
		"com_liferay_journal_content_web_portlet_JournalContentPortlet";

}


Which means that constant is the constant you are looking for if you want to target the web content portlet. So to reference this class in your project, you need to update your gradle -- I am assuming you are using gradle here emoticon. If you look at the bnd.bnd file in the journal-content-web project you will see the following --

Bundle-SymbolicName: com.liferay.journal.content.web
Bundle-Version: 1.0.8


So you take that and in your module where you want to reference it you add to your build.gradle dependencies section ...

compileOnly group: "com.liferay", name: "com.liferay.journal.content.web", version: "1.0.8"


.. the version being the minimum version you need for support. You could also use the Gogo shell to look up the meta data for this module and use the version from there in your dependency declaration.

That will allow you to reference it in your code and code against it but beware of course that gradle is a compile time, so this class has to be exported in order for the OSGI runtime to resolve it for you. I have come across a few cases where the class was not part of the exports (eg. LoginPortlet) so in those cases you have to either use a trick to make it exportable (David Nebinger did a blog post of this technique) or you just take the value from the constant and use it directly.

HTH
Heiko Ottenbacher, modifié il y a 6 années.

RE: Redirect to web content edit article page

New Member Publications: 20 Date d'inscription: 05/09/14 Publications récentes
Thank you very much, Andrew...

You helped me solving this problem even if your asumption was wrong, as I am using maven (actually it is an maven/spring mvc portlet i want to migrate to dxp) ;).
thumbnail
Andrew Jardine, modifié il y a 6 années.

RE: Redirect to web content edit article page

Liferay Legend Publications: 2416 Date d'inscription: 22/12/10 Publications récentes
Hahah -- no problem. I always assume that everyone is as obedient with Liferay out of the box tools and processes as I am but I have come to discover that there are a number of Liferay anarchists out there ;)

Best of luck with your migration.