3 Replies Latest reply on Apr 13, 2007 11:34 AM by Thomas Heute

    ActionRequest setAttribute

    Anette Engel Newbie

      According to the JSR 168 Spec PLT 11.1 PortletRquest Interface, Section PLT 11.1.13

      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
      .

      This suggests that an attribute set in the ActionRequest should be propagated to a JSP. But if I set an attribute in processAction:

      public void processAction(ActionRequest request, ActionResponse response) throws PortletException
      {
       // some processing done here ....
       request.setAttribute("myattribute", "some object");
      }


      then it does not get propagated to my JSP and the result of

      <% MyObject oby = (MyObject)renderRequest.getAttriubte("myattribute"); %>


      is null. Is this a bug or do I misinterpret the JSR 168 Spec?

      Either way it's a shame as this means I have to stick all information to the PortletSession even if it's related to a specific request. From Servlets I am used to sticking objects created while handling a request into a request attribute rather then a session attribute (unless it's information which I will need for future requests like user information).

      Best Regards,

      Anette

        • 1. Re: ActionRequest setAttribute
          Thomas Heute Master

          It would work if you put the setAttribute in the render method.

          Remember that the portal should be able to render your portlet without having to call the action method (only based on render parameters).

          Let's say it would work:
          - you set the object as an attribute in the action phase
          - the render phase of this portlet is called and displays the object.
          - now you rerender the page (refresh or click on another portlet for example)
          - it will call the render phase again (without having called the action phase that set the attibute) and your object will be null.


          You must set render parameters, then in the render phase set the attribute.



          • 2. Re: ActionRequest setAttribute
            Anette Engel Newbie

            O.K. I understand.

            Unfortunately using the render parameters is not an option as they are limited to string objects. (My processAction fetches tabular data from a database represented by an ArrayList).

            Thanks,

            Anette

            • 3. Re: ActionRequest setAttribute
              Thomas Heute Master

              You should fetch your data from your render phase.