Showing posts with label PortletURL. Show all posts
Showing posts with label PortletURL. Show all posts

Wednesday, July 08, 2015

Creating Portlet URLs


Listed below are various ways to create portlet action and render phase URLs

Creating URL within/to the current portlet.

1. Using Taglib:

For Render URL

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<portlet:renderURL var="myRenderURL1" windowState="<%=LiferayWindowState.NORMAL.toString()%>">
<portlet:param name="mvcPath" value="/html/view/myresponse.jsp"/>
</portlet:renderURL>

Similarly action URL looks like below
<portlet:actionURL var="myActionURL1" windowState="<%=LiferayWindowState.NORMAL.toString()%>">
<portlet:param name="cmd" value="update"/>
</portlet:actionURL>

2. Using Java code

For render URL
PortletURL myRenderURL2=renderResponse.createRenderURL();
myRenderURL2.setWindowState(LiferayWindowState.NORMAL);
myRenderURL2.setParameter("cmd", "view");
Similarly action URL looks like below
PortletURL myActionURL2=renderResponse.createActionURL();
myActionURL2.setWindowState(LiferayWindowState.NORMAL);
myActionURL2.setParameter("cmd", "update");

Creating URL outside the current portlet, that is URL to the other page or portlet.


PortletURL myRenderURL3= PortletURLFactoryUtil.create(request,  themeDisplay.getPortletDisplay().getId(), themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);

 myRenderURL3.setWindowState(LiferayWindowState.NORMAL);
 myRenderURL3.setPortletMode(LiferayPortletMode.VIEW);
 myRenderURL3.setParameter("jspPage", "/season/rainy.jsp");

Here themeDisplay.getPortletDisplay().getId() is the id of the current portlet to be viewed or it can be the id of the other portlet to be viewed and themeDisplay.getPlid() is the page layout Id of the current page and can point to the plid of some other page on which the portlet is deployed.