Necessary package need to Import in JSP page
    <%@ page import="com.liferay.portlet.PortletURLFactoryUtil"%>
    <%@ page import="com.liferay.portal.kernel.portlet.LiferayPortletURL"%>
    <%@ page import="javax.portlet.PortletRequest"%>
    <%@ page import="javax.portlet.PortletURL"%>
    <%@ page import="javax.servlet.http.HttpServletRequest"%>

Syntax:

portletURL URL = PortletURLFactoryUtil.create(request, portletId, plid, lifecycle);

OR

LiferayPortletURL URL = PortletURLFactoryUtil.create(request, portletId, plid, lifecycle);

For creating PortletRequest URL


ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
LiferayPortletURL renderURL = PortletURLFactoryUtil.create(request, portletId, plid, PortletRequest.RENDER_PHASE);
renderURL.setWindowState(WindowState.NORMAL); //to set windowsState
renderURL.setPortletMode(PortletMode.VIEW);  //to set portletmode
renderURL.setParameter(arg0,arg1);  /to set the parameter ex:ipcActionURL.setParameter("struts_action",/etc/reports/add);

LiferayPortletURL actionURL = PortletURLFactoryUtil.create(request, "portletId", plid, PortletRequest.ACTION_PHASE);
actionURL.setWindowState(WindowState.NORMAL); //to set windowsState
actionURL.setPortletMode(PortletMode.VIEW);  //to set portletmode
actionURL.setParameter(arg0,arg1);  /to set the parameter ex:ipcActionURL.setParameter("struts_action",/etc/reports/add);

PortletId:
          To fetch the current portletId or portletName.

            portletDisplay.getId();
            portletDisplay.getPortletName();

plid (Portlet Layout id):
         We need to mention plid, based on this plid it will redirect that particular
         page.//for InterPortlet communication(IPC)

<%= LayoutLocalServiceUtil.getFriendlyURLLayout(themeDisplay.getScopeGroupId(), false, "/layoutName").getPlid() %>

OR

<%=themeDisplay.getPlid()%>

Lifecycle/PortletRequest:
         Two types of portlet request we can use here.

  1.   PortletRequest.RENDER_PHASE
  2.   PortletRequest.ACTION_PHASE
  3.   PortletRequest.EVENT_PHASE
  4.   PortletRequest.RESOURCE_PHASE
  5.   PortletRequest.LIFECYCLE_PHASE
Advertisements

Comments on: "Create a URL based on PortletId in Liferay" (3)

  1. Hi,

    Thanks for the Detailed article. Is there a way to get the Instance id of the document library portlet from a custom portlet jsp page.

    Thanks
    Guru

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: