Foren

PrincipalThreadLocal.getUserId() is 0 for Icefaces (1.8.2) portlets

Parkash Kumar, geändert vor 6 Jahren.

PrincipalThreadLocal.getUserId() is 0 for Icefaces (1.8.2) portlets

New Member Beiträge: 10 Beitrittsdatum: 10.09.12 Neueste Beiträge
Hi,

I am basically implementing logger on the generic actions like saving portlet's preferences in store method of
PortletPreferencesImpl
. Here I am calling
PrincipalThreadLocal.getUserId()
to get user information. Everything is fine for the Liferay OTB's portlets and for Primefaces 5.2 portlets but when I am saving preferences of Icefaces (1.8.2) portlet, I am always getting 0 from
PrincipalThreadLocal.getUserId()
.

Why is this strange behavior?
Please share your valuable feedback.

Cross Posted: http://stackoverflow.com/questions/43116457/principalthreadlocal-getuserid-is-0-for-icefaces-1-8-2-portlets
thumbnail
Neil Griffin, geändert vor 6 Jahren.

RE: PrincipalThreadLocal.getUserId() is 0 for Icefaces (1.8.2) portlets

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
Hi Parkash,

What version of Liferay Portal are you using?

ICEfaces 1.8 is an outdated version of ICEfaces that requires JSF 1.2 (circa 2008) and is only supported up through Liferay Portal 6.2.

I think the problem you are encountering is caused by the fact that ICEfaces 1.8 only participates in the portlet lifecycle during the initial HTTP GET of the portal page. After that, all XHR requests go through the ICEfaces servlet, rather that a portlet lifecycle ResourceRequest. That would explain why Liferay's PrincipalThreadLocal is not working.

Are you able to upgrade to a more modern version of ICEfaces such as 4.1 or 4.2? Similar to PrimeFaces 5/6, those versions of ICEfaces utilize the portlet lifecycle via Liferay Faces Bridge.

Kind Regards,

Neil
Parkash Kumar, geändert vor 6 Jahren.

RE: PrincipalThreadLocal.getUserId() is 0 for Icefaces (1.8.2) portlets

New Member Beiträge: 10 Beitrittsdatum: 10.09.12 Neueste Beiträge
Thank you very much Neil for your response.

Yes, we have been using Liferay 6.2 and sorry we can't upgrade icefaces as we are totally moving to primefaces for newer development. Though, we have to provide support for our older version.

Well, I would like to share my investigation:
PrincipalThreadLocal.getUserId() is 0 in store() method of PortletPreferencesImpl when saving preferences any icefaces based portlet.

Reason:
For each request, com.liferay.portal.servlet.MainServlet.service:457 > setPrincipal:1305 of Liferay is responsible to set userId in PrincipalThreadLocal. However, for icefaces portlets Liferay's MainServlet does not get invoked, as there is exactly same named servlet (com.icesoft.faces.webapp.http.servlet.MainServlet) in icefaces jar, which gets invoked instead.

Traces:
Liferay OTB's / Primefaces portlets:
at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:523)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

Icefaces portlets:
at com.icesoft.faces.webapp.http.servlet.MainServlet.service(MainServlet.java:204)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
thumbnail
Neil Griffin, geändert vor 6 Jahren.

RE: PrincipalThreadLocal.getUserId() is 0 for Icefaces (1.8.2) portlets

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
Hi Parkash,

We have an ICEfaces 1.8 version of our jsf-applicant-portlet demo available. I recommend you study the source code in order to learn how to read/store portlet preferences.

One thing I'd like to mention is that the pom.xml descriptor contains an extra dependency that helps add JSR 329 style EL keywords (such as mutablePortletPreferencesValues), even though ICEfaces 1.8 does not utilize the JSR 329 bridge standard:

<dependency>
	<groupid>com.liferay.faces</groupid>
	<artifactid>com.liferay.faces.bridge.ice</artifactid>
	<version>2.0.0</version>
</dependency>


Kind Regards,

Neil