掲示板

Session Attributes missing between Event and Render Phases?

thumbnail
10年前 に Andew Jardine によって更新されました。

Session Attributes missing between Event and Render Phases?

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
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.


// code to get the results out of the event request here ...
eventRequest.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 --

renderRequest.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?
thumbnail
10年前 に Mika Koivisto によって更新されました。

RE: Session Attributes missing between Event and Render Phases?

Liferay Legend 投稿: 1519 参加年月日: 06/08/07 最新の投稿
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.
thumbnail
10年前 に Andew Jardine によって更新されました。

RE: Session Attributes missing between Event and Render Phases?

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
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..

  • Portlet A fires Event A
  • Portlet B captures Event A
  • Portlet B handler runs
  • Portlet B pushes value to its session attributes
  • Portlet B render handler runs
  • 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?
thumbnail
10年前 に Mika Koivisto によって更新されました。

RE: Session Attributes missing between Event and Render Phases?

Liferay Legend 投稿: 1519 参加年月日: 06/08/07 最新の投稿
I recommend reading the specification as it is the best source for accurate information on how things should work.
thumbnail
10年前 に Andew Jardine によって更新されました。

RE: Session Attributes missing between Event and Render Phases?

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
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?
thumbnail
10年前 に Joaquin Cabal によって更新されました。

RE: Session Attributes missing between Event and Render Phases?

Regular Member 投稿: 106 参加年月日: 09/09/07 最新の投稿
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);