I am trying to set the Session attribute [HTTP or Portlet Session] so that i can access it globally (through out the portal). But while getting the Session attribute its returning me the null instead of actual value.
SETTING the Session Attribute:
@Component(
immediate = true,
property = {
"com.liferay.portlet.display-category=IPC Sender",
"com.liferay.portlet.instanceable=true",
"javax.portlet.display-name=IPC_Sender Portlet",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/view.jsp",
"com.liferay.portlet.private-session-attributes=false",
"javax.portlet.resource-bundle=content.Language",
"javax.portlet.security-role-ref=power-user,user"
},
service = Portlet.class
)
public class ipcsenderPortlet extends MVCPortlet {
public void hello(ActionRequest actionRequest,
ActionResponse actionResponse) throws Exception
{
//Trying to set HttpSession but its also getting null while retrieving
HttpServletRequest httpreq = PortalUtil.getHttpServletRequest(actionRequest);
HttpSession session = httpreq.getSession(true);
session.setAttribute("transfer", "content");
////Trying to set Portletsession but its also getting null while retrieving
PortletSession portletsession = actionRequest.getPortletSession();
portletsession.setAttribute("sendvalue","abcde",
PortletSession.APPLICATION_SCOPE);
}
}
GETTING the Session Attribute in Different Portlet:
@Component(
immediate = true,
property = {
"com.liferay.portlet.display-category=IPC Receiver",
"com.liferay.portlet.instanceable=true",
"javax.portlet.display-name=IPC_Receiver Portlet",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/view.jsp",
"javax.portlet.resource-bundle=content.Language",
"com.liferay.portlet.private-session-attributes=false",
"javax.portlet.security-role-ref=power-user,user"
},
service = Portlet.class
)
public class ipcreceiverPortlet extends MVCPortlet
{
public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException
{
//HttpSession
HttpServletRequest httpreq = PortalUtil.getHttpServletRequest(renderRequest);
HttpSession session = httpreq.getSession();
String name = (String)session.getAttribute("transfer");
System.out.println("Session value through HttpSession:"+name);
//PortletSession
PortletSession portletsession = renderRequest.getPortletSession();
String userName = (String) portletsession.getAttribute("sendvalue",PortletSession.APPLICATION_SCOPE);
System.out.println("\nSession value through PortletSession:"+userName);
}
}