Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Andew Jardine
Session Attributes missing between Event and Render Phases?
April 9, 2013 1:34 PM
Answer

Andew Jardine

Rank: Expert

Posts: 260

Join Date: December 22, 2010

Recent Posts

Hey Guys,

I'm all out of ideas here so I amn hoping my issue is one someone else has seen before. Liferay portal 6.1 CE, Linux, Tomcat 7. I have two portlets ... a search portlet and a search results portlet. The user performs a search action. In the action Handler I fire on a SearchResultsEvent IPC event. The search results portlet listens for the event and when found, runs the event handler. This is all working.

In the event handler, I pull out a "Records" object and I push it into the session with the default PORTLET_SCOPE. I do this, like so.

1
2// code to get the results out of the event request here ...
3eventRequest.getPortletSession().setAttribute("records", results.getRecords());


In the render phase for the portlet I try to put the value from the session as a render attribute like so --
1
2renderRequest.setAttribute("records", renderRequest.getPortletSession().getAttribute("records"));


For some reason though null is always being passed through to the JSP. I debugged the code and found that the value IS going into the session during the event handler, but it is NOT there anymore in the render handler. The sessions both have the same ID so I'm not sure what is wrong.

Any chance that someone else has come across this before? knows how to get passed it? has a suggestion for what else I can try?
Mika Koivisto
RE: Session Attributes missing between Event and Render Phases?
April 9, 2013 5:18 PM
Answer

Mika Koivisto

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1501

Join Date: August 7, 2006

Recent Posts

If the portlets are in the same war file you can use application scope to get it working. If they are in different wars you need to find a different approach as that's not going to work.
Joaquin Cabal
RE: Session Attributes missing between Event and Render Phases?
April 10, 2013 6:10 AM
Answer

Joaquin Cabal

Rank: Junior Member

Posts: 49

Join Date: September 7, 2009

Recent Posts

Hi Andew,
Is like Mika said, you have to use ApplicationScope:

List result = (List) renderRequest.getAttribute("records",PortletSession.APPLICATION_SCOPE) //getting the data stored in other portlet
renderRequest.setAttribute("records", result);
Andew Jardine
RE: Session Attributes missing between Event and Render Phases?
April 10, 2013 7:20 AM
Answer

Andew Jardine

Rank: Expert

Posts: 260

Join Date: December 22, 2010

Recent Posts

Mika Koivisto:
If the portlets are in the same war file you can use application scope to get it working. If they are in different wars you need to find a different approach as that's not going to work.


I think maybe I explained it wrong, or you misunderstood. The porlets are in individual WARs, but the methods that are acting strange are in the SAME portlet. So the flow..

  1. Portlet A fires Event A
  2. Portlet B captures Event A
  3. Portlet B handler runs
  4. Portlet B pushes value to its session attributes
  5. Portlet B render handler runs
  6. Portlet B tries to retrieve value from session attributes added by handler


.. and that is where the issue arises. For some reason, within the same portlet, within the same (portlet) session the values are not there. I think what you thought I was trying to do is put something in the session with PortletB and have it accessed by PortletA. That is an alternative that I was going to try, but now I am less focused on solving the programming problem and fixated on what is happening with what I am trying to do now emoticon

Does that list explain it better?
Mika Koivisto
RE: Session Attributes missing between Event and Render Phases?
April 10, 2013 1:55 PM
Answer

Mika Koivisto

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1501

Join Date: August 7, 2006

Recent Posts

I recommend reading the specification as it is the best source for accurate information on how things should work.
Andew Jardine
RE: Session Attributes missing between Event and Render Phases?
April 10, 2013 5:35 PM
Answer

Andew Jardine

Rank: Expert

Posts: 260

Join Date: December 22, 2010

Recent Posts

Mika,

I will ahve another look at the spec but I don't know that what I am looking for is in there. My understanding is that there is an APPLICATION (scope) session that can be used to share values between portlets -- like a global space -- and that there is a PORTLET (scope) session that is created on a portlet by portlet basis. Regardless of which scope I apply to the problem, the variable should be "saved" an available in when I get to my render handler. In fact, from what I know/see, this is the only way to pass varaibles between the event processor (handler) and the render handler.

Is there another way to accomplish this that I am not aware of?