Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Cameron McBride
How to get the url to a portlet?
July 24, 2012 9:29 AM
Answer

Cameron McBride

Rank: Expert

Posts: 273

Join Date: February 8, 2011

Recent Posts

I am wanting to get the url to a portlet, so when the user clicks the link in portlet X it shows portlet Y full screen. I copied the below code and tweaked it from the "Create Account" code in login.jsp

1PortletURL myUrl = PortletURLFactoryUtil.create(
2  request, "helloWorld_WAR_HelloWorldPortlet", themeDisplay.getPlid(),
3  PortletRequest.RENDER_PHASE);
4
5myUrl.setWindowState(WindowState.MAXIMIZED);
6myUrl.setPortletMode(PortletMode.VIEW);


"helloWorld_WAR_HelloWorldPortlet" is the name of the portlet if you look in the plugins configuration in Liferay. When I click the link I end up with the Liferay junk at the top and no portlet at all.

The generated URL is:
http://localhost:8080/web/guest/home?p_p_id=helloWorld_WAR_HelloWorldPortlet&p_p_lifecycle=0&p_p_state=maximized&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1
Pinkesh Gandhi
RE: How to get the url to a portlet?
July 24, 2012 10:13 AM
Answer

Pinkesh Gandhi

Rank: Regular Member

Posts: 100

Join Date: January 26, 2012

Recent Posts

The generated URL is:
http://localhost:8080/web/guest/home?p_p_id=helloWorld_WAR_HelloWorldPortlet&p_p_lifecycle=0&p_p_state=maximized&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1


This is correct url for your portlet.

If you are using MVCPortlet / GenericPortlet then can you please attach the code of the doView(...) method of your portlet.
biswajit sarkar
RE: How to get the url to a portlet?
July 24, 2012 10:28 AM
Answer

biswajit sarkar

Rank: Regular Member

Posts: 166

Join Date: October 17, 2011

Recent Posts

use this code.....

 1public String renderPortlet1()throws Exception{
 2
 3FacesContext fc = FacesContext.getCurrentInstance();
 4ExternalContext ec = fc.getExternalContext();
 5PortletRequest pReq = (PortletRequest)ec.getRequest();
 6String portletInstaceId = getNameSpaceOfExistingComments(pReq, UniqueId);
 7final ThemeDisplay themeDisplay = (ThemeDisplay) pReq.getAttribute(WebKeys.THEME_DISPLAY);
 8HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(pReq);
 9httpRequest = PortalUtil.getOriginalServletRequest(httpRequest);
10PortletURL portletURL = PortletURLFactoryUtil.create(httpRequest ,portletInstaceId, themeDisplay.getPlid() ,PortletRequest.RENDER_PHASE);
11portletURL.setWindowState(WindowState.MAXIMIZED);
12portletURL.setPortletMode(PortletMode.VIEW);
13portletURL.setParameter(portletInstaceId, "docroot/xhtml/nav1/portletViewMode.xhtml");
14
15return portletURL.toString();
16}
Cameron McBride
RE: How to get the url to a portlet?
July 24, 2012 11:43 AM
Answer

Cameron McBride

Rank: Expert

Posts: 273

Join Date: February 8, 2011

Recent Posts

Pinkesh Gandhi:

If you are using MVCPortlet / GenericPortlet then can you please attach the code of the doView(...) method of your portlet.


That may be the problem. I have a requirement to use SpringMVC, with no ties to Liferay API, except for the few property files that are required. My controller looks like this:

 1@Controller
 2@RequestMapping("VIEW")
 3public class HelloWorldController {
 4   
 5    @RenderMapping()
 6    public String helloWorld(RenderResponse response) {
 7        return "index";
 8    }   
 9}


The portlet works great if you drag-n-drop it onto a page.

UPDATE:
I thought I should note that I am trying to show this portlet from another portlet. For example portlet x is on a page and portlet y is not. You click portlet x and it displays portlet y maximized.

In the login.jsp/create account example that I mimicked the portlet being maximized was the same as the portlet being used, not a different portlet.
Pinkesh Gandhi
RE: How to get the url to a portlet?
July 24, 2012 11:55 PM
Answer

Pinkesh Gandhi

Rank: Regular Member

Posts: 100

Join Date: January 26, 2012

Recent Posts

Hi Cameron,

Try with following scenario,

(1) Create one Page - Page ABC
(2) Put your portlet X on page ABC
(3) Create another Page in same community/organization and keep it Hidden - Page PQR
(4) Put your portlet Y on Page PQR

Now in your portlet X, create one PortletURL to display portlet Y from it and at that time you need to pass plId of the page PQR as a parameter(you can get plId of any page by using LayoutLocalServiceUtil).

For e.g.,

1
2PortletURL myUrl = PortletURLFactoryUtil.create(
3  request, "helloWorld_WAR_HelloWorldPortlet", "<plId-of-the-page-PQR>",  PortletRequest.RENDER_PHASE);
4
5myUrl.setWindowState(WindowState.MAXIMIZED);
6myUrl.setPortletMode(PortletMode.VIEW);


Now use this muUrl on a jsp of portlet X.
So when you click on the link/button the page PQR will be opened containing portlet Y in maximized mode.

I hope this may resolves your problem.

Let me know if you have any query.
Cameron McBride
RE: How to get the url to a portlet?
July 31, 2012 1:50 PM
Answer

Cameron McBride

Rank: Expert

Posts: 273

Join Date: February 8, 2011

Recent Posts

I needed to add the following to my liferay-portlet.xml file:
1<add-default-resource>true</add-default-resource>


After that it worked perfectly!