Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Angelika Morgan
URL Parameter
May 19, 2008 6:59 AM
Answer

Angelika Morgan

Rank: New Member

Posts: 23

Join Date: August 27, 2007

Recent Posts

Hello,

i have the following navigation structure:

home (http://localhost:8080/web/guest/home)
about (http://localhost:8080/web/guest/2)
contact (http://localhost:8080/web/guest/3)

How can i add parameter to the URL ?

Example:
http://localhost:8080/web/guest/home?myParam=1
http://localhost:8080/web/guest/2?myParam=2
http://localhost:8080/web/guest/3?myParam=3&myParam4=4

Thanks
Angelika
Aaron A'brook
RE: URL Parameter
May 19, 2008 3:33 PM
Answer

Aaron A'brook

Rank: New Member

Posts: 8

Join Date: May 18, 2008

Recent Posts

Just for curiosity, is it a parameter that will be used by the portlets within the page?
Angelika Morgan
RE: URL Parameter
May 19, 2008 11:34 PM
Answer

Angelika Morgan

Rank: New Member

Posts: 23

Join Date: August 27, 2007

Recent Posts

I need the Parameter for URL-Rewriting with "mod_rewrite" or "UrlRewriteFilter"
Aaron A'brook
RE: URL Parameter
May 20, 2008 11:24 PM
Answer

Aaron A'brook

Rank: New Member

Posts: 8

Join Date: May 18, 2008

Recent Posts

I'm not entirely sure about the answer but after some quick perusal of the liferay directory it looks like the urls must be stored within the liferay database. I can't view what's within the database at the moment but that's where I'd look next. This is for Liferay 5.0 by the way.
Brian Van Maurik
RE: URL Parameter
June 6, 2008 7:52 AM
Answer

Brian Van Maurik

Rank: New Member

Posts: 14

Join Date: July 12, 2007

Recent Posts

It has been my experience that you can send parameters like that, but by default, they are not passed to the portlets on the page.

The only way I have found that will work is if you include the portlet id and window state as parameters as well. This ends up looking something like this:

http://your.url/here?p_p_id=portletName_WAR_warFileName_INSTANCE_instanceId&p_p_state=normal&yourParam=someValue

This is not very practical, as the instance id will change every time you add a portlet to a page. Also, there is no way of knowing this without looking it up in the database first. I am currently searching for a way to get around this, but have not found it yet.
Ray Augé
Re: [Liferay Forums][3. Development] RE: URL Parameter
July 9, 2008 12:50 PM
Answer

Ray Augé

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1172

Join Date: February 7, 2005

Recent Posts

On Fri, 2008-06-06 at 14:52 +0000, Brian Van Maurik at Liferay's
Community Forums wrote:

> This is not very practical, as the instance id will change every time
> you add a portlet to a page. Also, there is no way of knowing this
> without looking it up in the database first. I am currently searching
> for a way to get around this, but have not found it yet.


This is a limitation of the jsr-168 spec. In 5.0+ you have options such
as portlet events and shared render parameters in order to push params
to several portlets (or to portlets registering the shared params.

Also, the fact that you need the p_p_id and windows state is part of the
spec... so we're stuck with it.

Next, a very nice and clean way to pass parameters which is both spec
compliant and easy to work with is by implementing a FriendlyURLMapper
class for you portlet. This allows you to have a human readable URL and
also interprets parameters however you've formatted your URL. See for
example, the MessageBoard URLs, the Wiki URLs, Blog URLs, etc..

HTH!


----------------------------------
Raymond Augé
Software Engineer
Liferay, Inc.
Enterprise. Open Source. For Life.
----------------------------------
Liferay Meetup 2008 – Los Angeles

August 1, 2008

Meet and brainstorm with the creators of Liferay Portal, our partners
and other members of our community!

The day will consist of a series of technical sessions presented by our
integration and services partners. There is time set aside for Q&A and
corporate brainstorming to give the community a chance to give feedback
and make suggestions!

View Event Details

Register Now
Fuad Efendi
RE: Re: [Liferay Forums][3. Development] RE: URL Parameter
July 9, 2008 1:23 PM
Answer

Fuad Efendi

Rank: Regular Member

Posts: 169

Join Date: April 5, 2007

Recent Posts

Hi Ray,

I am currently using FriendlyURLMapper with altered Asset Publisher & Articles; and I hardly construct those URLs (to be shown in Asset Publisher) like this:

viewURL = articleLayoutUrl + XML.encodeTitleForUrl(asset.getTitle()) + "/" + articlePortletID.substring(12) + "/" + articleResource.getArticleId();

(where 'Layout' is a page).

I think method
public String buildPath(LiferayPortletURL portletURL)
can do it much better but I don't know how to use it from JournalArticleDisplay (or another class) instance...

Thanks
Fuad Efendi
RE: URL Parameter
July 9, 2008 2:28 PM
Answer

Fuad Efendi

Rank: Regular Member

Posts: 169

Join Date: April 5, 2007

Recent Posts

Angelika,

mod_rewrite part of Apache HTTPD frontend, and you can 'rewrite' everything, for instance:
/15/0/M/V -> ?p_p_id=15&p_p_lifecycle=0&p_p_state=maximized&p_p_mode=view

URLRewriteFilter is for Java-based web application, it won't work with Liferay (a lot of redirects, unpredictable/random URLs/namespaces, AJAX, variable length of parameters, etc.)

Easiest plugin point to make URLs friendly: look at FriendlyURLMapper...
Fuad Efendi
RE: URL Parameter
July 9, 2008 3:03 PM
Answer

Fuad Efendi

Rank: Regular Member

Posts: 169

Join Date: April 5, 2007

Recent Posts

I believe renderResponse.createRenderURL(); is the answer, and Liferay builds friendly URLs with .toString() - need to confirm... I noticed in WIKI portlet only such code, and it builds URLs like http://localhost:8080/web/test/home/wiki/Main/Child1
Ray Augé
RE: URL Parameter
July 10, 2008 6:42 AM
Answer

Ray Augé

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1172

Join Date: February 7, 2005

Recent Posts

Yes Fuad, simply creating a portlet url and calling the .toString() method on it will result in a Friendly URL provided one is defined for the portlet in question... and also will depend on the parameters defined for the portlet URL.

i.e. it is possible for a single FriendlyURLMapper class to allow for many different mappings to a given portlet. The different mappings can be based on the phase of the portletURL (action, render, resource) and/or can be based on parameters defined.

The message board portlet provides an example of this. See MBFriendlyURLMapper.
Fuad Efendi
RE: URL Parameter
July 15, 2008 1:05 PM
Answer

Fuad Efendi

Rank: Regular Member

Posts: 169

Join Date: April 5, 2007

Recent Posts

Thanks Ray,


it coresponds to JSR-168, and Liferay takes care about friendlyness

But how to build friendly URL from one portlet to another portlet, such as from AssetPublisher to JournalContent (placed on same page)? I currently hardcoded it, as a sample
viewURL = articleLayoutUrl + "/" + articlePortletID + "/" + articleResource.getArticleId() + "/" + templateId;


Hope there is better solution. I know I can instantiate Journal Content with WindowState.MAXIMIZED at runtime; what if already I have an instance on a page?
Torsten Krah
RE: Re: [Liferay Forums][3. Development] RE: URL Parameter
December 11, 2008 3:36 AM
Answer

Torsten Krah

Rank: New Member

Posts: 4

Join Date: August 12, 2008

Recent Posts

Looking at the URL Mapper this seems a good way to do things.
But i need to use "the base friendly url" configured in the ThemeDisplay.

How can this be done?
I want to use the friendlyURL configured for this page in my URLMapper class to be portable.
Is this possible?

Or is the path build prefiexed already with the configured friendlyUrlPath from themeDisplay.