留言板

Liferay 7 (CE GA3) shared attributes between portlets

Damien Guillermet,修改在7 年前。

Liferay 7 (CE GA3) shared attributes between portlets

Junior Member 帖子: 44 加入日期: 15-7-9 最近的帖子
Hello,

I would like to know if it's possible to share an attribute between 2 portlets/bundles for a single user only.
I can set an attribute in the portlet session via :

portletSession.setAttribute("LIFERAY_SHARED_test", "value", PortletSession.APPLICATION_SCOPE);


I'm using Liferay Faces so i retrieved the portlet session like
final PortletSession portletSession = ((PortletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getPortletSession();


At this step I'm able to get the attribute in all portlet A instances :
portletSession.getAttribute("LIFERAY_SHARED_test", PortletSession.APPLICATION_SCOPE); // Returns "value"


And it's only accessible for current user so it works as excepted. But I also want to get this attribute from other portlets (B, C, ...), and even if I set the configuration private-session-attributes to false in portlets I get null from portlets B.

BTW is there a difference if the private-session-attributes is defined via liferay-portlet.xml (legacy) or via OSGI component annotations ?

If someone knows a workaround I'll be very grateful to share it.

Best regards,
Damien.
thumbnail
David H Nebinger,修改在7 年前。

RE: Liferay 7 (CE GA3) shared attributes between portlets

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
Damien Guillermet:
But I also want to get this attribute from other portlets (B, C, ...), and even if I set the configuration private-session-attributes to false in portlets I get null from portlets B.


Sessions are still separate on a per-portlet basis. Instead of using portlet session, you could use http session instead.

That said, session storage is a horrible crutch. For me, using session means you haven't figured out how to communicate w/ the browser or the data sink or both.

Session storage negatively affects your nodes ability to serve users. Plus you either need to replicate session throughout the cluster (another performance hit and resource consumer) or be okay with losing session data if the node crashes.

It seems like an easy way to span requests (and in your case share data), but therein lies the trap.

BTW is there a difference if the private-session-attributes is defined via liferay-portlet.xml (legacy) or via OSGI component annotations ?


No difference whatsoever, they both have the same outcome.
thumbnail
Neil Griffin,修改在7 年前。

RE: Liferay 7 (CE GA3) shared attributes between portlets

Liferay Legend 帖子: 2655 加入日期: 05-7-27 最近的帖子
If you are using JSF then I would recommend that you do not use private-session-attributes=false since it is a Liferay-specific feature that does not work well with the standards based JSR 329/378 FacesBridge spec, implemented by Liferay Faces Bridge. I am not aware of any JSF portlet projects that have successfully used private-session-attributes=false. For example, there are two issues in the Liferay Faces issue tracker that are either closed/inactive.
Damien Guillermet,修改在7 年前。

RE: Liferay 7 (CE GA3) shared attributes between portlets

Junior Member 帖子: 44 加入日期: 15-7-9 最近的帖子
Hello Neil, David,
thanks for your advices. I have redefined my requirements and I finally use on one hand the IPC client (Liferay.fire...) mecanism and on the oher hand user custom fields (via expando bridge).
By the way I use Liferay Faces in this project for example ;)
Damien.
thumbnail
Neil Griffin,修改在7 年前。

RE: Liferay 7 (CE GA3) shared attributes between portlets

Liferay Legend 帖子: 2655 加入日期: 05-7-27 最近的帖子
Hi Damien,

Thanks for letting us know that you found a workable solution. Also, thanks for using Liferay Faces! emoticon

Neil