组合视图 统一视图 树状图
讨论主题 [ 上一个 | 下一个 ]
toggle
Ignacio Santos Alonso
Same view in all instances of a portlet
2013年9月17日 上午8:14
答复

Ignacio Santos Alonso

等级: Junior Member

帖子: 41

加入日期: 2013年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:

 1
 2public static String getPreference(final String name) {
 3    PortletPreferences preferences = PortletPreferencesFactoryUtil.getPreferences(getHttpServletRequest());   
 4    return preferences.getValue(name, null);
 5    }
 6
 7public static void setPreference(final String name, final String value)
 8        throws ReadOnlyException, ValidatorException, IOException {
 9   
10    PortletPreferences preferences = PortletPreferencesFactoryUtil.getPreferences(getHttpServletRequest());
11    preferences.setValue(name, value);
12    preferences.store();
13    }
Kyle Joseph Stiemann
RE: Same view in all instances of a portlet
2013年9月17日 上午8:37
答复

Kyle Joseph Stiemann

LIFERAY STAFF

等级: Regular Member

帖子: 158

加入日期: 2013年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
RE: Same view in all instances of a portlet
2013年9月17日 上午9:22
答复

Ignacio Santos Alonso

等级: Junior Member

帖子: 41

加入日期: 2013年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.
Ignacio Santos Alonso
RE: Same view in all instances of a portlet
2013年9月17日 上午9:29
答复

Ignacio Santos Alonso

等级: Junior Member

帖子: 41

加入日期: 2013年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.
Kyle Joseph Stiemann
RE: Same view in all instances of a portlet
2013年9月17日 上午9:57
答复

Kyle Joseph Stiemann

LIFERAY STAFF

等级: Regular Member

帖子: 158

加入日期: 2013年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:

1
2<portlet>
3
4    ...
5
6    <preferences-owned-by-group>false</preferences-owned-by-group>
7</portlet>


- Kyle
Ignacio Santos Alonso
RE: Same view in all instances of a portlet
2013年9月23日 上午3:02
答复

Ignacio Santos Alonso

等级: Junior Member

帖子: 41

加入日期: 2013年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.
Kyle Joseph Stiemann
RE: Same view in all instances of a portlet
2013年9月26日 上午10:17
答复

Kyle Joseph Stiemann

LIFERAY STAFF

等级: Regular Member

帖子: 158

加入日期: 2013年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
Jose Jimenez
RE: Same view in all instances of a portlet
2013年9月27日 上午12:16
答复

Jose Jimenez

LIFERAY STAFF

等级: Regular Member

帖子: 129

加入日期: 2012年8月22日

最近的帖子

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
RE: Same view in all instances of a portlet
2013年9月27日 上午1:48
答复

Ignacio Santos Alonso

等级: Junior Member

帖子: 41

加入日期: 2013年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.
Juan Gonzalez
RE: Same view in all instances of a portlet
2013年9月27日 上午2:10
答复

Juan Gonzalez

LIFERAY STAFF

等级: Liferay Legend

帖子: 1984

加入日期: 2008年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
RE: Same view in all instances of a portlet
2013年9月27日 上午3:39
答复

Ignacio Santos Alonso

等级: Junior Member

帖子: 41

加入日期: 2013年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!