掲示板

Problem with portlet scope (?)

9年前 に Marko Perić によって更新されました。

Problem with portlet scope (?)

Junior Member 投稿: 52 参加年月日: 14/09/03 最新の投稿
Hello,

I developed a portlet that fetch data through webservice and shows it in a search container. My problem is that all users are using the same instance of portlet. Example: if person A fetch some data, when person B log in it can see this same data as person A. P.S. I don't have any static variable.

What I have to do so users have their own instance with them-specific data?
thumbnail
9年前 に Olaf Kock によって更新されました。

RE: Problem with portlet scope (?)

Liferay Legend 投稿: 6403 参加年月日: 08/09/23 最新の投稿
With regards to application state Portlets are just like Servlets: They should not have any member variables - no matter if static or not. Typically the portlet container (Liferay) creates only a single object of a portlet's class ever - but this is an implementation detail. All of your application's state goes into the request or response that's passed into the various lifecycle methods. If necessary, utilize the session that you'll find in the request, but there certainly are antipatterns regarding too much data in the session.

99% of all member variables in a portlet are signalling an architectural mistake. The remaining percent is divided up between loggers and other member variables with similar purpose.
9年前 に Marko Perić によって更新されました。

RE: Problem with portlet scope (?)

Junior Member 投稿: 52 参加年月日: 14/09/03 最新の投稿
Olaf Kock:
With regards to application state Portlets are just like Servlets: They should not have any member variables - no matter if static or not. Typically the portlet container (Liferay) creates only a single object of a portlet's class ever - but this is an implementation detail. All of your application's state goes into the request or response that's passed into the various lifecycle methods. If necessary, utilize the session that you'll find in the request, but there certainly are antipatterns regarding too much data in the session.

99% of all member variables in a portlet are signalling an architectural mistake. The remaining percent is divided up between loggers and other member variables with similar purpose.


Thanks Olaf, yes I assumed it is a problem, I have a list of people as a member variable. I wanted to decrease pressure on database because of pagination (I tried not to contact database every time page of list changes) and very large number of users (and much communication with database) but obviously it's not possible :/
thumbnail
9年前 に Olaf Kock によって更新されました。

RE: Problem with portlet scope (?)

Liferay Legend 投稿: 6403 参加年月日: 08/09/23 最新の投稿
Well, it is possible. Just not with member variables at the portlet object - a portlet's state is in the request/response. You can also have another (global level) cache and just have the cache keys in the portlet state.

There literally is no difference to a servlet in this regard - there exactly the same would happen, by design.
9年前 に Marko Perić によって更新されました。

RE: Problem with portlet scope (?)

Junior Member 投稿: 52 参加年月日: 14/09/03 最新の投稿
Thank you Olaf, I'll try that emoticon
9年前 に Marko Perić によって更新されました。

RE: Problem with portlet scope (?)

Junior Member 投稿: 52 参加年月日: 14/09/03 最新の投稿
I have tried some solutions like Peter posted here: https://www.liferay.com/web/pmesotten/blog/-/blogs/user-specific-versus-shared-portlet-preferences-part-1#alqy_message_47970038.

I set in liferay-portlet parameters: preferences-company-wide, preferences-unique-per-layout and preferences-owned-by-group:

       <portlet>
		<portlet-name>people-list</portlet-name>
		<icon>/icon.png</icon>
		<preferences-company-wide>false</preferences-company-wide>
		<preferences-unique-per-layout>true</preferences-unique-per-layout>
		<preferences-owned-by-group>false</preferences-owned-by-group>
		<header-portlet-css>/css/main.css</header-portlet-css>
		<footer-portlet-javascript>
			/js/main.js
		</footer-portlet-javascript>
		<css-class-wrapper>people-list-portlet</css-class-wrapper>
	</portlet>


But problem remains, two logged users see the same data, if person A change data, it's changed for person B also. Also, situation is the same when I use two different browsers as a Liferay Guest role, without authentication to liferay.

Could somebody help me please?
thumbnail
9年前 に Olaf Kock によって更新されました。

RE: Problem with portlet scope (?)

Liferay Legend 投稿: 6403 参加年月日: 08/09/23 最新の投稿
So you're using PortletPreferences? Because in your initial question you just ruled out static member variables. It might help to post your portlet's code (or just the relevant portions - don't post 100s of lines)