1 Reply Latest reply on Oct 12, 2005 8:42 PM by Viet

    PortletRequest - attributes

    Bradley Smith Master

      Hello,

      If I set a request attribute in processAction() on ActionRequest which extends PortletRequest, I find that it is not available during render() on the RenderRequest which also extends PortletRequest. I have reviewed the JSR spec and quoted relevant sections below. From my review, it seems to me like there is some ambiguity. In PLT.11.1.3, request attributes are intented "...to express information that otherwise could not be expressed via the API." From PLT.11.4, it seems like there isn't necessarily a guarantee that the objects placed in request scope during processAction() are available in render().

      If the attributes are not going to be preserved going from processAction() to render() for a single portlet, then what is the point of setting request attributes during processAction()? Since you don't get a RenderRequest-view of the same PortletRequest later on in render(), who are you communicating with (from a portlet perspective)? If the portlet API supports the concept of setting request attributes, I think it would be nice to be able to retrieve these same request attributes during the render() phase of a portal request. Ideally, the ActionRequest and the RenderRequest can be two different 'views' of a single PortletRequest during a request process.

      I realize that I can use PortletSession to 'communicate' between processAction() and render() phases, but then I must also remember to remove my attributes from PortletSession if these attributes are really only valid for a single request.

      Thoughts?

      Thanks,
      Brad Smith


      From JSR 168 Specification


      PLT.11.1.3 Request Attributes

      Request attributes are objects associated with a portlet during a single portlet request. Request attributes may be set by the portlet or the portlet container to express information that otherwise could not be expressed via the API. Request attributes can be used to share information with a servlet or JSP being included via the PortletRequestDispatcher. Attributes are set, obtained and removed using the following methods of the

      PortletRequest interface:
      ? getAttribute
      ? getAttributeNames
      ? setAttribute
      ? removeAttribute

      Only one attribute value may be associated with an attribute name.
      Attribute names beginning with the ?javax.portlet.? prefix are reserved for definition by this specification. It is suggested that all attributes placed into the attribute set be named in accordance with the reverse domain name convention suggested by the Java Programming Language Specification 1 for package naming.

      ....

      PLT.11.2 ActionRequest Interface

      The ActionRequest interface extends the PortletRequest interface and it is used in the processAction method of the Portlet interface. In addition to the functionality provided by the PortletRequest interface, the ActionRequest interface gives access to the input stream of the request.

      PLT.11.3 RenderRequest Interface

      The RenderRequest interface extends the PortletRequest interface and is used in the render method of the Portlet interface. Currently, the RenderRequest interface does not define any additional method.

      PLT.11.4 Lifetime of the Request Objects

      Each request object is valid only within the scope of a particular processAction or render method call. Containers commonly recycle request objects in order to avoid the performance overhead of request object creation. The developer must be aware that maintaining references to request objects outside the scope described above may lead to
      non-deterministic behavior


        • 1. Re: PortletRequest - attributes
          Viet Master

          Hello Brad,

          the request attributes are not intended to be shared between the action and the render. Doing that would be a "bad" practice because it does not enforce a clean MVC. Furthermore in JBoss Portal 2.2 there is a request dispatching between the action phase and the render phase i.e :

          1/ process action
          2/ portal sends a redirect to render
          3/ render

          That means that any attribute set during the action is lost for the render.

          You should use the render parameters from the action to pass a string, otherwise you need to use the portlet session to do that.