留言板

Same view in all instances of a portlet

Ignacio Santos Alonso,修改在10 年前。

Same view in all instances of a portlet

Junior Member 帖子: 50 加入日期: 13-2-12 最近的帖子
Hi, I'm having a strange problem. I don't seem to find anyone else who happened to to deal with the same issue but I hope to get some orientation at least.

I have an instanciable portlet (<instanceable>true</instanceable>) with preferences. It's been built with Liferay faces. Once it is setup in the edit mode I store the parameters in a session bean.

The strange thing is that all the instances of the portlet show the same configuration... so it's like having the same portlet repeated over the pages. Whenever I change the configuration on any of the portlets, the changes apply to all the instances in all the pages. It's the same not only for instances inside the same page but also for instances in different pages! It looks like Liferay is sharing the portlet preferences and session data for all the instances!! However I checked that the instances are in fact different, when I take a look at the portlet configuration I can see a different name for every instance:
(portletName)_INSTANCE_iQ1F
(portletName)_INSTANCE_Nz8R
etc

Any clues? I'm kind of lost here.

PS. A little bit of code:
-This is how I'm getting and setting the preferences:


public static String getPreference(final String name) {
    PortletPreferences preferences = PortletPreferencesFactoryUtil.getPreferences(getHttpServletRequest());	
	return preferences.getValue(name, null);
    }

public static void setPreference(final String name, final String value)
	    throws ReadOnlyException, ValidatorException, IOException {
	
    PortletPreferences preferences = PortletPreferencesFactoryUtil.getPreferences(getHttpServletRequest());
	preferences.setValue(name, value);
	preferences.store();
    }
thumbnail
Kyle Joseph Stiemann,修改在10 年前。

RE: Same view in all instances of a portlet

Liferay Master 帖子: 760 加入日期: 13-1-14 最近的帖子
Hi Ignacio,
It seems like your problem is due to <preferences-company-wide> being set to true in your liferay-portlet.xml file. This overrides any other settings such as <preferences-unique-per-layout>. Please remove the line <preferences-company-wide>true</preferences-company-wide>, if you have it in your liferay-portlet.xml, and let us know if that fixes the problem.

- Kyle
Ignacio Santos Alonso,修改在10 年前。

RE: Same view in all instances of a portlet

Junior Member 帖子: 50 加入日期: 13-2-12 最近的帖子
Kyle Joseph Stiemann:
Hi Ignacio,
It seems like your problem is due to <preferences-company-wide> being set to true in your liferay-portlet.xml file. This overrides any other settings such as <preferences-unique-per-layout>. Please remove the line <preferences-company-wide>true</preferences-company-wide>, if you have it in your liferay-portlet.xml, and let us know if that fixes the problem.

- Kyle


Hi Kyle,

My portlet doesn't use that setting in the liferay-portlet.xml file. The portal is a Liferay 6.0 EE SP2 freshly started so the portal configuration is also the default.
I removed the "static" modifiers from the methods that get and set the preferences but the behavior is the same. Still, as I said before, it doesn't seem to affect the way it works in the end.
I must add that I changed from another JSF library/bridge to Liferay faces because I thought it would solve the problem. So maybe it's got something to do with the JSF techonolgy or my code... don't know.

Thanks anyway.
thumbnail
Kyle Joseph Stiemann,修改在10 年前。

RE: Same view in all instances of a portlet

Liferay Master 帖子: 760 加入日期: 13-1-14 最近的帖子
Hi Igancio,
Sorry, I was looking at the wrong entity. <preferences-company-wide> is set to false by default so that isn't the problem. The is another entity called <preferences-owned-by-group> which is set to true by default, and it sets the preferences for the portlet to be owned by the group when the portlet is shown in a group page. If it is set to false, the preferences are owned by the user at all times. Try putting <preferences-owned-by-group>false</preferences-owned-by-group> into the liferay-portlet.xml file in the <portlet> section:


<portlet>

    ...

    <preferences-owned-by-group>false</preferences-owned-by-group>
</portlet>


- Kyle
Ignacio Santos Alonso,修改在10 年前。

RE: Same view in all instances of a portlet

Junior Member 帖子: 50 加入日期: 13-2-12 最近的帖子
Hi Kyle,

Thanks again for your answer.
I applied the setting you recommended but the portlet still behaves the same way: I install in a page and configure the first portlet and when I install the same portlet in another page of the same community it is a exact copy of the first one. In fact, my portlet should show a different page if it hasn't been configured and it doesn't because it is already configured like the first instance from the start.
However, once I modify the second instance it behaves as desired. So, as I said before, this is not an issue for me any more because the portlet does work but still there seems to be some session data sharing going on and I don't know if it's the portlet's fault or my code's.
thumbnail
Kyle Joseph Stiemann,修改在10 年前。

RE: Same view in all instances of a portlet

Liferay Master 帖子: 760 加入日期: 13-1-14 最近的帖子
I tried to reproduce your issue using the JSF2-portlet, but everything seems to work as expected. I deployed the JSF2 portlet, changed the preferences, and then deployed a new JSF2 portlet to another page. That seemed to work fine, and each portlet had it's own preferences. Could you possibly attach a small sample portlet which has this problem to your post so that I can test this?

Thanks,
Kyle
thumbnail
Jose Jiménez,修改在10 年前。

RE: Same view in all instances of a portlet

Regular Member 帖子: 176 加入日期: 12-8-23 最近的帖子
Hi Ignacio,

Have you managed beans at session scope? In affirmative case take in account that the properties of these beans can't be declared as static in order to be "thread safe" and not shared throught all objects (and sessions).

http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html

I hope this help you, check your code trying to find the root cause.

Kind Regards!
Jose
Ignacio Santos Alonso,修改在10 年前。

RE: Same view in all instances of a portlet

Junior Member 帖子: 50 加入日期: 13-2-12 最近的帖子
Thank you both Kyle and Jose,

I had already noticed that I had static modifiers on my session bean, which I used in order to have a direct access to some variables that are shared across the application. I removed them but I just noticed that I left some others unremoved in another class. And yes, this may be the cause of the problem.

However, imho, wouldn't it be better if Liferay isolated every instance of the portlet by default? I don't see why I can't make use of static variables in session classes. I mean, Liferay itself should make sure that there is no memory sharing between instances of the same portlet unless the user configures it to do otherwise (liferay-portlet.xml)

Anyway, since this might be the cause of the problem I'll take a look at it when I have the time.

Thanks again for your support.

Cheers.
thumbnail
Juan Gonzalez,修改在10 年前。

RE: Same view in all instances of a portlet

Liferay Legend 帖子: 3089 加入日期: 08-10-28 最近的帖子
Hi Ignacio,

Liferay deals with session attributes when deploying instanceable portlets, so they won't be shared.

But this (static) modifiers, belonging to same WAR, hasn't anything to do with Liferay. I mean, as any other J2EE webapp, will be shared no matter where's deployed.
Ignacio Santos Alonso,修改在10 年前。

RE: Same view in all instances of a portlet

Junior Member 帖子: 50 加入日期: 13-2-12 最近的帖子
Thank you Juan,

Liferay does make space for different instances of Liferay when the portlet is instanceable (which in the end just means allocating different memory spaces), so I thought that it could also allocate different memory spaces for the same application by default and only allow memory sharing when the user explicitly specifies it in the liferay-portlet.xml file.

I do understand however the current behavior of the portal and will try to adapt my portlet to it.

Thanks and good weekend!
Ignacio Santos Alonso,修改在10 年前。

RE: Same view in all instances of a portlet

Junior Member 帖子: 50 加入日期: 13-2-12 最近的帖子
After configuring each instance I can make the portlets work in a different way, but as I said before, in the beginning they all look the same and share the configuration.
These are the steps I followed:
1- Install the portlet in a page and configure it.
2- Install the portlet in another page. Surprisingly, this second portlet shares the same parameters that I configured for the first one.
3- Change the portlet configuration in the second page, it works as desired.
4- When I go back to the first page the first portlet hasn't changed and keeps the configuration that I set on the first step. It also works as desired.
So this problem doesn't seem to affect the portlet's functionality but it's still strange to see that unexpected share of information in the beginning.