Forum

Accueil » Liferay Portal » English » 3. Development

Vue combinée Vue Plate Arborescence
Sujets [ Précédent | Suivant ]
toggle
Andew Jardine
Session Attributes missing between Event and Render Phases?
9 avril 2013 13:34
Réponse

Andew Jardine

Rang: Regular Member

Publications: 240

Date d'inscription: 22 décembre 2010

Publications Récentes

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 avril 2013 17:18
Réponse

Mika Koivisto

LIFERAY STAFF

Rang: Liferay Legend

Publications: 1498

Date d'inscription: 7 août 2006

Publications Récentes

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 avril 2013 06:10
Réponse

Joaquin Cabal

Rang: Junior Member

Publications: 49

Date d'inscription: 7 septembre 2009

Publications Récentes

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 avril 2013 07:20
Réponse

Andew Jardine

Rang: Regular Member

Publications: 240

Date d'inscription: 22 décembre 2010

Publications Récentes

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 avril 2013 13:55
Réponse

Mika Koivisto

LIFERAY STAFF

Rang: Liferay Legend

Publications: 1498

Date d'inscription: 7 août 2006

Publications Récentes

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 avril 2013 17:35
Réponse

Andew Jardine

Rang: Regular Member

Publications: 240

Date d'inscription: 22 décembre 2010

Publications Récentes

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?