6 Replies Latest reply on Jul 18, 2006 3:32 PM by bdaw

    sharing data between render() and processAction() method

    hubertg

      Hi,

      I need to share data between the render() and the processAction() method.

      The method of (my) choice (and I think the only? method) is using the PortletSession:

      render() :

      request.getPortletSession("sharedData", value);
      


      processAction();
      Object data = request.getPortletSession("sharedData");
      // do something with data
      


      my question is now:

      is there anything problematic about sharing data via the PortletSession?

      I could think of problems because of the fact that the processAction and the render request are seperate http requests. is there the possibilty that a 3rd render request comes between these two?

      something like that
      REQUEST 1
      portletX.processAction()
      ---------------------------------------<<<< REQUEST 3 ???
      ---------------------------------------<<<< portletX.render();
      ---------------------------------------<<<< portletY.render();
      ---------------------------------------<<<< portletZ.render();
      REQUEST 2 (because of server redirect)
      portletX.render()
      portletY.render()
      portletZ.render()

      I would be very happy if someone could bring some light into this, although i'm not sure, if I made myself clear ...

      thanks in advance.

        • 1. Re: sharing data between render() and processAction() method
          hubertg

          correction:
          of course i meant

          request.getPortletSession().setAttribute("sharedData", value);

          and
          Object data = request.getPortletSession().getAttribute("sharedData");


          an edit function would be great ... :-)

          • 2. Re: sharing data between render() and processAction() method
            bdaw

            for string values just use:

            PortletURL url = response.createActionURL();
            url.setParameter(?paymentMethod?,?creditCardInProfile?);


            I'm not sure in which order you want to pass those objects.

            If render --> action
            Your concerns are correct. Render phase for a portlet can be triggered multiply times with unpredictable order beetween portlets on the same page and you have no influence on this.

            If action --> render
            You simply use ActionRequest.setAttribute(), RenderRequest.getAttribute() or ActionRequest.setRenderParameter() which is better practice than using a session

            • 3. Re: sharing data between render() and processAction() method
              hubertg

              thanks for your answer.

              The order is:

              1. processAction() portlet A
              2. render() portlet A
              3. render() portlet B
              4. render() other portlests C,D, ...

              I'm porting a MVC web framework (WebWork 1) into a portlet. The classical MVC approach is based on one atomic request-response cycle. The action class needs the input parameters, creates a ValueStack (the action's result) which is passed to the jsp pages via request attributes. In the portlet I have to split this process into two phases, namely the processAction and the render phase. Therefore I need a way to pass the ValueStack from the processAction phase to the render phase.

              I think render params are no solution for my problem because first I don't want to make results directly visible for the user and second it's practically impossible to set java objects as render objects.

              br, hubert

              • 4. Re: sharing data between render() and processAction() method
                bdaw

                you do ActionRequest.setAttribute(Object o) and RenderRequest.getAttribute(...)

                Consider using MVC web framework that has bridge/support for portlets. JSF and struts has some.

                And read portlet specification (jsr-168) - it's not very long and really readable ;)

                • 5. Re: sharing data between render() and processAction() method
                  hubertg

                  I may be wrong, but I think by using your suggested commands the Object o won't be accessible in the RenderRequest. If it were I'd happily use this method of sharing objects between the methods.

                  The only way is to use ActionResponse::setRenderParameter(String). Then the renderparameter is simply added to the url used for redirect (/portal/default/?renderparam1=value).

                  Render and ActionREquest are two different HTTPServletRequest and not sharing any objects. Thats at least what I remember from JSR 168 :-)

                  JSF and struts are no real alternatives because the current system is based on webwork 1. I used the StrutsBridge as some kind of inspiration though.

                  • 6. Re: sharing data between render() and processAction() method
                    bdaw

                    arf... ok. of course your right. I wrote the anwser to fast and it is wrong. sory for that.... very stupid from my side.