views:

88

answers:

2

Hi, I am new to portlets and have a question about how they work in CMS portals ( we are evaluating LifeRay as a CMS ).

Let's say, for example, I would like to create a portlet to display all the books required for a particular course. You don't have to be logged in to see this, it will appear on public website.

In the CMS, I will create two pages for ENGL-100 and HIST-300.

I want to add the same portlet on each page. I expect to deploy the portlet as a war file.

How will I tell the portlet on each page which course to look up? Don't tell me I have to change the portlet.xml file for each subject. Does a portlet have any access to URL parameters?

A: 

Yes, portlets can process URL parameters. That's the way you'd go to implement what you want. Depending on the page you are visiting, you just pass the course subject as a URL parameter and let the portlet process it for you. Of course you have to go to the database to look for the right course, etc to return the proper data.

Leniel Macaferi
Can't I set a variable when I place the portlet on a page? Would it be impossible to put 2 of the same portlets on the same page, each referencing a different course?
jeph perro
You can put 2 instances of a portlet on the same page. Just change the URL parameter when configuring the portlet's properties page. For each portlet pass a different courseId, so that it can get the proper course data from the database.
Leniel Macaferi
In JSR portets, you *should not* parse URL parameters, see below for more details
jayshao
+2  A: 

Portlets should not rely on URL parameters directly - for this exact reason - you might have multiple instances on the same page, and don't want them to collide (since they'll all see the params during Render, though only one will get Action)

In Liferay, you can just drop 2 portlets, and if you use Preferences through an EDIT or Liferay Config view, the prefs will be scoped separately to render initial state. The container will handle keeping the 2 portlets straight.

jayshao