Search code examples
jspliferaystruts-1

Getting current user in Liferay 6.2 (themeDisplay always null)


I try to get the id of current user in jsp page usinge :

<%@page import="com.liferay.portal.theme.*" %>
<%@page import="com.liferay.portal.kernel.util.WebKeys" %>
<portlet:defineObjects />
<liferay-theme:defineObjects />
<%
themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
User objUser=themeDisplay.getUser(); 
%>    

but themeDisplay return always null !!

I have also tried to get it in my struts action using :

public class acces extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ThemeDisplay themeDisplay =
(ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
Long currentuser = themeDisplay.getUserId();

but still return null

i'm using liferay 6.2 ce, webmodule struts 1.2 deployed into liferay as war file using install in appManager.

Please help, i'm missing some configurations?


Solution

  • Following by your reply to my initial question...

    If your Struts application can be added, it means that it has at least a portlet.xml file inside (I don't know if Liferay Application Manager add it for you)... in any case you can't access to context in this way.

    The best way to create a portlet application by Struts, is using Struts Portlet Bridge ; how you can see in the link I provided it allows to your code to become compliant with JSR specifications; then it should be able to rigth interact with portlet container...

    You can just try with one action and test if it solves your problem... the conversion between standard web application to portlet application should be as painless as possible.