SHARE
TWEET

Untitled

a guest Jul 17th, 2017 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Component(
  2. immediate = true,
  3. property = {
  4.     "com.liferay.portlet.display-category=IPC Sender",
  5.     "com.liferay.portlet.instanceable=true",
  6.     "javax.portlet.display-name=IPC_Sender Portlet",
  7.     "javax.portlet.init-param.template-path=/",
  8.     "javax.portlet.init-param.view-template=/view.jsp",
  9.     "com.liferay.portlet.private-session-attributes=false",
  10.     "javax.portlet.resource-bundle=content.Language",
  11.     "javax.portlet.security-role-ref=power-user,user"
  12. },
  13. service = Portlet.class
  14. )
  15.  
  16. public class ipcsenderPortlet extends MVCPortlet {
  17.  
  18. public void hello(ActionRequest actionRequest,
  19.         ActionResponse actionResponse) throws Exception
  20. {  
  21. //Trying to set HttpSession but its also getting null while retrieving
  22. HttpServletRequest httpreq = PortalUtil.getHttpServletRequest(actionRequest);
  23. HttpSession session = httpreq.getSession(true);
  24. session.setAttribute("transfer", "content");
  25.  
  26. ////Trying to set Portletsession but its also getting null while retrieving
  27. PortletSession portletsession = actionRequest.getPortletSession();
  28. portletsession.setAttribute("sendvalue","abcde",
  29. PortletSession.APPLICATION_SCOPE);
  30. }
  31. }
  32.    
  33. @Component(
  34.     immediate = true,
  35.     property = {
  36.         "com.liferay.portlet.display-category=IPC Receiver",
  37.         "com.liferay.portlet.instanceable=true",
  38.         "javax.portlet.display-name=IPC_Receiver Portlet",
  39.         "javax.portlet.init-param.template-path=/",
  40.         "javax.portlet.init-param.view-template=/view.jsp",
  41.         "javax.portlet.resource-bundle=content.Language",
  42.         "com.liferay.portlet.private-session-attributes=false",
  43.         "javax.portlet.security-role-ref=power-user,user"
  44.     },
  45.     service = Portlet.class
  46. )
  47. public class ipcreceiverPortlet extends MVCPortlet
  48. {
  49.     public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException
  50.     {
  51.         //HttpSession
  52.          HttpServletRequest httpreq = PortalUtil.getHttpServletRequest(renderRequest);
  53.          HttpSession session = httpreq.getSession();
  54.          String name = (String)session.getAttribute("transfer");
  55.          System.out.println("Session value through HttpSession:"+name);
  56.  
  57.          //PortletSession
  58.          PortletSession portletsession = renderRequest.getPortletSession();
  59.          String userName = (String) portletsession.getAttribute("sendvalue",PortletSession.APPLICATION_SCOPE);
  60.          System.out.println("nSession value through PortletSession:"+userName);
  61.     }
  62. }
RAW Paste Data
Top