Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 无法获取Liferay登录的用户ID_Jsf_Liferay - Fatal编程技术网

Jsf 无法获取Liferay登录的用户ID

Jsf 无法获取Liferay登录的用户ID,jsf,liferay,Jsf,Liferay,我正在尝试获取liferay用户ID(我在liferay 7中使用primefaces 6.2) 到目前为止,我尝试的是: HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); ThemeDisplay td =(ThemeDisplay)request.getAttribute(WebKeys.THEME_D

我正在尝试获取liferay用户ID(我在liferay 7中使用primefaces 6.2)

到目前为止,我尝试的是:

HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();

ThemeDisplay td  =(ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
long userId = td.getUserId();
我得到以下错误:

ERROR [stderr] (default task-49) java.lang.ClassCastException: com.liferay.faces.bridge.ext.filter.internal.ResourceRequestBridgeLiferayImpl cannot be cast to javax.servlet.http.HttpServletRequest
我搜索了这个问题,但没有找到有效的解决办法。任何帮助都将不胜感激

提前谢谢


我还尝试使用PortletRequest。下面是代码

PortletRequest request = (PortletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();

ThemeDisplay td  =(ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
User user = td.getUser();
但现在找不到主题显示类

java.lang.NoClassDefFoundError: com/liferay/portal/theme/ThemeDisplay: javax.el.ELException: java.lang.NoClassDefFoundError: com/liferay/portal/theme/ThemeDisplay
我不知道我在哪里失踪了


感谢

要获取Liferay用户对象,您可以使用以下代码段:

FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
User u = PortalUtil.getUser(portletRequest);
还请阅读有关ExternalContext.getRequest()返回值的内容-这可能是您的强制转换错误的原因。
文章进一步解释说:“ExternalContext.getRequest()方法返回一个
对象,而不是
javax.servlet.http.HttpServletRequest
。当在门户中使用此方法时,该对象可以转换为javax.portlet.PortletRequest。”

因此,实际上您的问题与JSF无关了……谢谢!可以从外部链接添加一个小的提取吗?一个10字的摘要或类似的?@Kukeltje我更新了我的答案,向OPS提供了一些信息。谢谢你的回复。我尝试了上面的代码,现在我得到了Portal Util的NoClassDefFound错误<代码>警告[javax.enterprise.resource.webcontainer.jsf.lifecycle](默认任务-10)java.lang.NoClassDefFoundError:com/liferay/portal/util/PortalUtil:javax.el.ELException:java.lang.NoClassDefFoundError:com/liferay/portal/util/PortalUtil位于com.sun.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:187)在com.sun.el.parser.AstValue.invoke(AstValue.java:289)
上,这很奇怪。它通常是门户内核的一部分,并作为全局Tomcat库安装。可以在您的捆绑包中搜索门户内核吗?@Andre Albert:我正在使用与Wildfly和maven存储库捆绑的Liferay 7。Portal-kernel-5.2.3.jar在Maven依赖项中提供。但是错误仍然是显示PortalTil的NoCLassDefFound。