Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Jason Cantrell
FriendlyURLMapper question
July 30, 2009 9:02 AM
Answer

Jason Cantrell

Rank: Junior Member

Posts: 44

Join Date: February 28, 2008

Recent Posts

Hi all,

I have a question about the basic functionality of the FriendlyURLMapper within Liferay.

My question is: when using the FriendlyURLMapper, will the friendly URL display the whole page that the portlet resides on, or will it display only the portlet itself?

I'm trying to use one of my custom portlets from my Liferay site that is in production in another web portal. The other portal has a portlet that displays external web content when a URL is provided. I'd like it to only display my custom portlet if possible.

I have my FriendlyURLMapper class written, and as it is now it displays the whole page that the portlet is on. If this is the way that the FriendlyURLMapper is supposed to work, does anyone have any suggestions for getting a URL to display just my custom portlet?
Wilson Man
RE: FriendlyURLMapper question
July 30, 2009 12:03 PM
Answer

Wilson Man

LIFERAY STAFF

Rank: Liferay Master

Posts: 577

Join Date: June 21, 2006

Recent Posts

you can have it so it only displays your portlet ... What you want to do is in the populateParams(...) method, add this:

1addParam(params, "p_p_state", WindowState.MAXIMIZED.toString());
Jason Cantrell
RE: FriendlyURLMapper question
July 30, 2009 12:31 PM
Answer

Jason Cantrell

Rank: Junior Member

Posts: 44

Join Date: February 28, 2008

Recent Posts

Thanks for the reply and good tip, Wilson!

One more question: When using the friendly URL, what has to come before it?

For example: If I'm using it from my local tomcat server, would it be just "http://localhost:8080/friendly_url" ? Or would I have to precede it with the URL for the page that the portlet is on, ie. "http://localhost:8080/web/guest/5/friendly_url" ?
Wilson Man
RE: FriendlyURLMapper question
July 30, 2009 4:42 PM
Answer

Wilson Man

LIFERAY STAFF

Rank: Liferay Master

Posts: 577

Join Date: June 21, 2006

Recent Posts

precede it with the layout URL, then a /-/, and then your friendlyURL mapping ...

so let's say you have a layout called /home/about which your portlet (the one with the friendlyURLMapper)
and a friendlyURL mapping of "contact-us"

then to "hit" your mapper, the is the URL: http://<domain>:<port>/home/about/-/contact-us/<the-rest-of-your-friendly-parameters>
Jason Cantrell
RE: FriendlyURLMapper question
August 3, 2009 8:49 AM
Answer

Jason Cantrell

Rank: Junior Member

Posts: 44

Join Date: February 28, 2008

Recent Posts

In my previous research into the friendlyURLMapper, I learned that the /-/ delimiter was added into the friendlyURLMapper functionality in versions 5.0 and up of Liferay. I'm working on a site using Liferay 4.4. Would the URL used to "hit" my mapper be any different that what you described?
Wilson Man
RE: FriendlyURLMapper question
August 3, 2009 10:26 AM
Answer

Wilson Man

LIFERAY STAFF

Rank: Liferay Master

Posts: 577

Join Date: June 21, 2006

Recent Posts

yeah, it won't use the /-/ like you said ... other than that, i'm not sure what else is different ...
Jason Cantrell
RE: FriendlyURLMapper question
August 4, 2009 11:44 AM
Answer

Jason Cantrell

Rank: Junior Member

Posts: 44

Join Date: February 28, 2008

Recent Posts

Wilson -

First of all, you rock for answering all of my questions.

Second - you mentioned a "layout URL" a couple posts ago. I don't believe I have one. I never set one up and I'm not using a custom layout. So what would the URL be like if I didn't have a layout URL?
Wilson Man
RE: FriendlyURLMapper question
August 5, 2009 7:16 PM
Answer

Wilson Man

LIFERAY STAFF

Rank: Liferay Master

Posts: 577

Join Date: June 21, 2006

Recent Posts

i'm no longer familiar with 4.4.x ... but in the version i'm currently doing my work on (5.2.x), when you're managing the pages (layouts) within the community, you can specify a friendlyURL for that page/layout. If you can't find it, maybe it doesn't exist in 4.4.x yet? But I vaguely remember that it should have it ...

Either way, I'm not sure what the URL would look like without the friendly layout URL ... but I saw in another post that you were able to trigger your HDFriendlyURLMapper ... so maybe you've already figured it out?
Jason Cantrell
RE: FriendlyURLMapper question
August 6, 2009 9:12 AM
Answer

Jason Cantrell

Rank: Junior Member

Posts: 44

Join Date: February 28, 2008

Recent Posts

Yeah, I figured out the URL issue.

I also finally figured out the issue I was having in the other thread I posted. This portlet actually acts as two different portlets, depending on which action is needed. And as a result, it has two possible portlet IDs depending on which version of the portlet is currently being displayed. I solved the problem by splitting my HDFriendlyURLMapper class up into two classes (one for each portletID).

But now I'm back to my original problem: properly displaying this portlet in the other portal.

When I hit the friendlyURL in the other portal, it displays the portlet and it seems to be maximized, but it still displays the banner and tab bar at the top of my Liferay page above the portlet.

Here's the code for one of my friendlyURLMapper classes (except for the portlet ID and URL, they are identical):

 1package com.ext.portlet.helpdesk;
 2
 3import com.liferay.portal.kernel.portlet.BaseFriendlyURLMapper;
 4import com.liferay.portal.kernel.portlet.LiferayPortletURL;
 5import com.liferay.portal.kernel.util.GetterUtil;
 6import com.liferay.portal.kernel.util.StringPool;
 7import com.liferay.portal.kernel.util.StringUtil;
 8import com.liferay.portal.kernel.util.Validator;
 9import org.apache.struts.config.ActionConfig;
10
11import java.util.Map;
12
13import javax.portlet.PortletMode;
14import javax.portlet.WindowState;
15
16
17public class HD2FriendlyURLMapper extends BaseFriendlyURLMapper {
18
19    public String getMapping() {
20        return _MAPPING;
21    }
22
23    public String getPortletId() {
24        return _PORTLET_ID;
25    }
26
27
28
29    public String buildPath(LiferayPortletURL portletURL) {
30
31        String friendlyURLPath = null;
32       
33       
34        friendlyURLPath = "/help_desk/register";
35
36
37        return friendlyURLPath;
38    }
39
40    public void populateParams(String friendlyURLPath, Map params) {
41
42        params.put("p_p_id", _PORTLET_ID);
43        params.put("p_p_action", "0");
44        params.put("p_p_state", WindowState.MAXIMIZED.toString());
45        params.put("p_p_mode", PortletMode.VIEW.toString());
46
47        addParam(params, "p_p_state", WindowState.MAXIMIZED.toString());
48
49    }
50
51
52
53    private static final String _MAPPING = "help_desk/register";
54
55
56    private static final String _PORTLET_ID = "EXT_HELPDESK2";
57
58}


As you can see it's pretty barebones at this point. Any other changes I can make to the params to make just the portlet display?

And thanks again for all your help Wilson.
Wilson Man
RE: FriendlyURLMapper question
August 6, 2009 7:05 PM
Answer

Wilson Man

LIFERAY STAFF

Rank: Liferay Master

Posts: 577

Join Date: June 21, 2006

Recent Posts

MAXIMIZED will still show the portal's page headers and footers. If you don't want those either, you have to go with this:
1LiferayWindowState.EXCLUSIVE


But i'm not sure if that window state is in 4.4.x ...
Jason Cantrell
RE: FriendlyURLMapper question
August 10, 2009 11:47 AM
Answer

Jason Cantrell

Rank: Junior Member

Posts: 44

Join Date: February 28, 2008

Recent Posts

Just wanted to let you (and anybody else) know that that window state is in Liferay 4.4.

Thanks again for all the help Wilson.