user212218
user212218

Reputation:

Can multiple pages share the same instance of a portlet in Liferay?

For a website powered by Liferay EE 6.0 SP1, there will be cases where some pages will need to "share" the same instance of certain portlets, but other pages will have their own instances.

For example (contrived, but hopefully illustrative), consider a portlet with a preference that changes the portlet's background color.

Suppose that we have the following pages (the portlet's background color on that page follows the page name in this list):

Home          (green)
├─ About      (blue)
│  └─ Contact (blue)
├─ Products   (orange)
│  ├─ AXL-900 (orange)
│  └─ VCC-218 (orange)
├─ Support    (red)
│  └─ VIP     (gold)
└─ Legal      (green)

Note that on several pages, the portlet has the same background color preference. So far, that's easy enough; you just add a separate instance of the portlet to each page and set the preference appropriately.

However, the content managers don't want to manage the background color on a per-page basis; they want to, for example, change the background color for the portlet on all the "About" pages to purple, all at the same time (this makes sense; it automates what would otherwise be a manual [and by definition, error-prone] process).

For this to work, either the "About" and "Contact" pages, for example, would both have to use the same instance of the portlet... or they would have to have separate instances, but both instances would share the same preference values. Or perhaps there is a different approach.

Is there a way to make this work?

Upvotes: 5

Views: 2802

Answers (3)

mvmn
mvmn

Reputation: 4057

Yes, this is possible by creating non-instancable portlet, and using a scope for those pages. Here's Liferay wiki page on scopes: http://www.liferay.com/community/wiki/-/wiki/Main/Scope

UPD: There are also a couple of Liferay-specific settings that allow you to control scope for portlet preferences: "preferences-company-wide", "preferences-unique-per-layout" and "preferences-owned-by-group" (all are set/unset via liferay-portlet.xml).

More on them here: http://content.liferay.com/4.3/doc/devel/liferay_4_portlet_development_guide/multipage/ch02.html And here: http://www.liferay.com/community/forums/-/message_boards/message/10931559/maximized

Upvotes: 0

user212218
user212218

Reputation:

It looks like the way to go is to create named sets of settings and let each page have its own instance of the portlet.

In the example from the OP, the Products page would have a unique instance of the portlet which would be configured to use e.g., the "orange" setting set. Any changes made to the portlet's settings would subsequently affect any other portlets using the "orange" setting set.

See http://www.liferay.com/community/forums/-/message_boards/message/10361805#_19_message_10382903 for more information.

Upvotes: 1

mico
mico

Reputation: 12748

You're having a custom portlet of your own and you want it to be instanceable or non-instanceable depending on the placement where it is deployed, right? (As said on the link on your comment)

One possibility is to deploy another version of your portlet with slightly different name (portlet1 vs. portlet2) and now on another one (portlet1) you have setting instanceable and in another (portlet2) you have it non-instanceable. This is not a nice way, but some out of the box thinking.

Also if you could otherwise configure the instanciable thing so that some portlet window gets that setting on and another off, it would be perfect, but I don't know much about that. Maybe the all knowing Google or someone else can help in his/her own answer.

Btw. Why don't ask on comments the answering person on the another question also to look this one?

Edit_1: After your comment I researched the issue again and found out Portlet Prefences property, whose application was described on Liferay pages and one forum. At least one comment on the forum I mentioned was near to the behavior you were talking about. Also the Liferay pages had examples of possibly interesting type of settings.

Upvotes: 0

Related Questions