9 Replies Latest reply on Oct 18, 2005 3:55 AM by poyge394

    forward from processAction

    poyge394

      how can i forward to one jsp file from processAction method
      i try res.sendRedirect("edit.jsp");
      but i get HTTP Status 404

        • 1. Re: forward from processAction
          poyge394

          no samples ? ...
          i have a form in one jsp, when i push the button one portlet calls. from the portlet i whant to go to other jsp file.
          how do i do that plez

          • 2. Re: forward from processAction
            jlaskowski

            Hi,

            I don't know about samples (which I guess should be a part of some kind of JBoss Portal tutorial) so I can't point you out to one, but...

            When the form is submitted, it executes processAction(). I assume that you use appropriate <portlet:actionURL/> tag, otherwise it won't work. In processAction, doView() or other doXXX() actually, you can do whatever you want with the application flow - when a given parameter is passed on redirect a request to another JSP page using RequestDispatcher.include(). It should answer your question.

            If you don't want to bother about the redirection you could take a look at MyFaces project which comes with a portlet - MyFacesGenericPortlet that is a bridge between JSF and portlet worlds. It's so easy to design a flow in JSF, and you can do it declaratively, in XML. It's tested and works.

            Jacek

            • 3. Re: forward from processAction
              poyge394

              ok tanks. but how do i get the RenderRequst and RenderResponse object from the processAction method.
              i most have them for user RequestDispacher

              • 4. Re: forward from processAction
                poyge394

                 

                 public void processAction(ActionRequest req, ActionResponse res)
                 throws IOException, PortletException {
                 String calcAction = req.getParameter( "calcAction" );
                 if( calcAction != null ) {
                 int nbr1 = Integer.parseInt( req.getParameter( "number1" ) );
                 int nbr2 = Integer.parseInt( req.getParameter( "number2" ) );
                 int result = nbr1 + nbr2;
                 System.out.println(result);
                 }
                 PortletRequestDispatcher prd =
                 getPortletContext().getRequestDispatcher(jspDir + "edit.jsp");
                 prd.include(); // I MOST HAVE RenderRequest and RenderResponse Objects
                
                 }
                
                


                • 5. Re: forward from processAction
                  danch1

                  processAction doesn't produce output, render does. After your processAction is called, render will be called at least once, allowing your portlet to produce output. This is the core difference between the servlet and portlet request models.

                  Bear in mind that render may be called multiple times (as other portlets perform actions, for example) so it should not itself make any changes in application state. You can use ActionResponse.setRenderParameter to pass (String) parameters from the processAction method to the render method, if needed.

                  What exactly are you trying to do? Does the JSP actually make changes in application state, or is it just your display mechanism?

                  • 6. Re: forward from processAction
                    poyge394

                    tanks for the answer...i havent yet test your solution...what exactly do u mean with change state ? .... my flow is this:

                    1. portlet doView method send yout to one jsp file with one form in it.
                    2. when the user submit, processAction is called.
                    3. now from the processAction i whant to get prameter and then put it in the attribute list of the actionResponse.
                    4. then i whant display another jsp file, that jsp file get the value that are in the attribute list.

                    i hope u anderstand better what i try to do. in servlet world it would be very eayse, i dont understand why it is so difficult hear

                    • 7. Re: forward from processAction
                      danch1

                      After your processAction completes, doView should get called again (assuming your portlet is still in 'view' mode - if not, doEdit or doHelp will be).

                      One idea for you is to put the JSP you want to display into a render parameter in your processAction method and look for that in your doView method.

                      The reason behind all this convolution is that in a portal there will be multiple portlets displayed on the user's screen at one time. Any one of them may post back to the server, at which point only that one should actually perform an action but the rest should refresh their views. To accomplish this, the spec splits processing into an 'action' phase (that is only done by the portlet that was the target of the post) and the 'render' phase (that is done by every portlet on the page (unless their output is cached by the portal server))

                      Hope this helps.
                      -danch

                      • 8. Re: forward from processAction

                        indeed and I need to add that since JBoss Portal 2.2 there is a request dispatch done between the action and the request to ensure that semantic better.

                        "danch" wrote:
                        After your processAction completes, doView should get called again (assuming your portlet is still in 'view' mode - if not, doEdit or doHelp will be).

                        One idea for you is to put the JSP you want to display into a render parameter in your processAction method and look for that in your doView method.

                        The reason behind all this convolution is that in a portal there will be multiple portlets displayed on the user's screen at one time. Any one of them may post back to the server, at which point only that one should actually perform an action but the rest should refresh their views. To accomplish this, the spec splits processing into an 'action' phase (that is only done by the portlet that was the target of the post) and the 'render' phase (that is done by every portlet on the page (unless their output is cached by the portal server))

                        Hope this helps.
                        -danch


                        • 9. Re: forward from processAction
                          poyge394

                          thanks...