WebSphere Portal Server - request.getAttribute returns null when an action occurs in another portlet on same pag

This is Interesting: Free IT Magazines  
Home > Archive > WebSphere Portal Server > December 2005 > request.getAttribute returns null when an action occurs in another portlet on same pag





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author request.getAttribute returns null when an action occurs in another portlet on same pag

2005-12-19, 2:50 am

In my action class of a portlet, I set an attribute to the PortletRequest, and then try to retrieve it in my JSP. This works fine while rendering the JSP the first time.

But when an action occurs inside a SECOND portlet that is on the same page, then the JSP in the first portlet loses the data that was displayed earlier.

It is clear that when an action occurs in the SECOND portlet, the JSP in the first portlet is re-rendered but the action class is not getting called. And the request.getAttribute("xxx") returns null in the JSP.

I want to know if this is a limitation in Struts IBM Portlet? And how it can be overcome. How do I avoid losing this data?

Code sample is as follows:

-----------------------------------------------------
IN THE ACTION CLASS:

public ActionForward performAction(ActionMapping mapping, ActionForm form, User user, HttpServletRequest request, HttpServletResponse response) throws Exception
{
ActionErrors errors = new ActionErrors();
ActionForward forward = new ActionForward(); // return value
PortletRequest portletRequest = (PortletRequest) request;

try
{
portletRequest.setAttribute("xxx");
}
}
-----------------------------------------------------
IN THE JSP:

<--This is inside a scriplet
String x = (String) request.getAttribute("xxx");
System.out.println("Value of x:" + x );
%>
-----------------------------------------------------

In the JSP, the value of "x", will display fine the first time.
But, on an action in another portlet, the "Value of x:" comes as null



2005-12-23, 7:51 am

This is the standard behaviour.
Only the render phase of the first portlet will happen, so the action class is never called.
When using Struts, Portal caches the Form Bean when an action class runs. So when only the render phase happens, it just uses the cached form bean and re runs the jsp.
This is all explained better in the documentation and Portal redbook.
Rather than setting values in the request, you should set them on your Form Bean. That way the value will still be there when the JSP runs the second time.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com