[jboss-user] [JBoss Portal] - Re: How can I get current portal user from javax.portlet.Por

csagar do-not-reply at jboss.com
Mon Apr 28 07:08:23 EDT 2008


Hi freesoul.
i am stuck with the same problem of retriving the current logge in user of the portal.I have this code with me,

--------------------------------------------------------------------------------------
/*****************************************
 *                                       *
 *  JBoss Portal: The OpenSource Portal  *
 *                                       *
 *   Distributable under LGPL license.   *
 *   See terms of license at gnu.org.    *
 *                                       *
 *****************************************/

package org.jboss.portlet1.hello;

import java.io.IOException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;

import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.UnavailableException;

import org.jboss.portal.api.PortalRuntimeContext;
import org.jboss.portal.api.navstate.NavigationalStateContext;
import org.jboss.portal.api.session.PortalSession;
import org.jboss.portal.core.controller.ControllerContext;




public class HelloWorldJSPPortlet extends GenericPortlet implements PortalRuntimeContext
{
	private ControllerContext ctx;
	private PortalSession psession;
	private String userId;
	/*private UserProfileModule userProfileModule;*/
	
   /*@Override
	public void init(PortletConfig config) throws PortletException {
		// TODO Auto-generated method stub
		super.init(config);
		userProfileModule = (UserProfileModule)getPortletContext().getAttribute("UserProfileModule");
	}*/

protected void doView(RenderRequest rRequest, RenderResponse rResponse) throws PortletException, IOException, UnavailableException
   {
      rResponse.setContentType("text/html");

      //PortalRuntimeContext context=(PortalRuntimeContext)this.getPortletContext();
      //userId=context.getUserId();
      //ControllerContext ctx;
      
      //userId=getUserId();
      
      //System.out.println("user:"+userId);
      
      String sYourName = (String) rRequest.getParameter("yourname");
      
      if(sYourName != null)
      {
         rRequest.setAttribute("yourname", sYourName);
         PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/view2.jsp");
         prd.include(rRequest, rResponse);
      }
      else
      {
    	  //rRequest.setAttribute("yourname", userId);
         PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/view.jsp");
         prd.include(rRequest, rResponse);
      }
   }



   public void processAction(ActionRequest aRequest, ActionResponse aResponse) throws PortletException, IOException, UnavailableException
   {
      String sYourname = (String) aRequest.getParameter("yourname");
      
      // do something

      aResponse.setRenderParameter("yourname", sYourname);
   }

   protected void doHelp(RenderRequest rRequest, RenderResponse rResponse) throws PortletException, IOException, UnavailableException
   {
      rResponse.setContentType("text/html");
      PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/help.jsp");
      prd.include(rRequest, rResponse);
   }

   protected void doEdit(RenderRequest rRequest, RenderResponse rResponse) throws PortletException, IOException, UnavailableException
   {
      rResponse.setContentType("text/html");
      PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/edit.jsp");
      prd.include(rRequest, rResponse);
   }

public NavigationalStateContext getNavigationalStateContext() {
	// TODO Auto-generated method stub
	return null;
}

public PortalSession getSession() {
	// TODO Auto-generated method stub
	return null;
}

public String getUserId() {
	// TODO Auto-generated method stub
	//((org.jboss.portlet.JBossActionRequest) PortletContext
		//	.getActionRequest()).getUser();
	return null;
	
	
}
   
   
}
-----------------------------------------------------------------------------
This is the sample code provided in helloworldjspportlet zip here---

I need to get the current user of the system to display a jsp page in the portlet. According to docs ,i tried to implement the PortalRuntimeContext interface , but no success.....

You seem to be successful in it.however i am not using the struts framework. is it possible to retrieve the current user ? 

waiting for reply.

thanks 
csagar

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4147163#4147163

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4147163



More information about the jboss-user mailing list