Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Andew Jardine
Session Attributes missing between Event and Render Phases?
9 de Abril de 2013 13:34
Resposta

Andew Jardine

Ranking: Expert

Mensagens: 323

Data de entrada: 22 de Dezembro de 2010

Mensagens recentes

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?
9 de Abril de 2013 17:18
Resposta

Mika Koivisto

LIFERAY STAFF

Ranking: Liferay Legend

Mensagens: 1505

Data de entrada: 7 de Agosto de 2006

Mensagens recentes

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?
10 de Abril de 2013 06:10
Resposta

Joaquin Cabal

Ranking: Junior Member

Mensagens: 49

Data de entrada: 7 de Setembro de 2009

Mensagens recentes

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?
10 de Abril de 2013 07:20
Resposta

Andew Jardine

Ranking: Expert

Mensagens: 323

Data de entrada: 22 de Dezembro de 2010

Mensagens recentes

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?
10 de Abril de 2013 13:55
Resposta

Mika Koivisto

LIFERAY STAFF

Ranking: Liferay Legend

Mensagens: 1505

Data de entrada: 7 de Agosto de 2006

Mensagens recentes

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?
10 de Abril de 2013 17:35
Resposta

Andew Jardine

Ranking: Expert

Mensagens: 323

Data de entrada: 22 de Dezembro de 2010

Mensagens recentes

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?