Announcement Announcement Module
Collapse
No announcement yet.
Request parameters How to Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Request parameters How to

    Hi,

    I have a problem with the request. My params are all empty. I don't know how to pass parameters to one page to another in Spring.

    I put my parameters in the ModelAndView of the submit procedure and I try to get they in the formBackingObject but the request is empty.

    In the other hand, I use a succes view that redirect my page to the another. How can I get the parameters?

    Thanks,

    Praedos

  • #2
    As you mention the formBackingObject method, I assume you're working with forms and want set form properties from the request when the form first loads.

    If so, in your form config make sure you have the following in your config

    Code:
    <property name="bindOnNewForm" value="true"/>

    Comment


    • #3
      Hi Sprang,

      It's that you said. I want to get the value of a field, a simple string.

      I try to do this but don't run.

      I use the SimpleFormController.

      Perhaps the problem is that I do forward to a web that redirect to another web in the onSubmit() method.

      Code:
      mav.addObject("url","UW0009HeadForm.htm");
      mav.setViewName("UW0000_Cigna_Succes");
      In this web I do this:

      Code:
      <c:redirect url="${url}"/>
      That is correct?

      Comment


      • #4
        setSuccessView("redirect:/ URL")
        return new ModelAndView(getSuccessView());

        Comment


        • #5
          Request parameters How to

          Thank you,

          I use this that you said but the problem continues.

          To request my parameters I do this:

          In onSubmit:

          Code:
          mav.addObject("parameter", "myParameter");
          In formBackingObject:

          Code:
          System.out.println(request.getParameter("parameter"));
          It's correct?

          Comment


          • #6
            I dont think putting objects in the mv is the same as adding it to the HttpServletRequest .

            What you will have to do is add the parameters to the url itself.

            http://mysite.com?myparameter=val1

            Comment


            • #7
              Not work

              Greetings,

              It's doesn't work.

              The request is empty in the other controller.

              Thank you

              Comment


              • #8
                I can use the expresion ${user} in my JSP to use and object added on my ModelAndView of the page before.

                How can I use this value in my formBackingObject method?

                Comment


                • #9
                  nobody knows?

                  Comment


                  • #10
                    OK!

                    In my opinion. The parameters are lost were I pass from the controller to a page that redirect to another page.

                    The problem is: How can I happen directly from a page to other one without intermediate pages?

                    Thanks to all!

                    Praedos

                    Comment


                    • #11
                      When I try to do

                      Code:
                      setSuccessView("redirect:/UW0008LetterForm");
                      I have the error:

                      Code:
                      org.apache.jasper.JasperException: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'headerCommand' available as request attribute

                      Comment


                      • #12
                        Can you explain exactly what you're trying to acheive (the flow of the pages)

                        Comment


                        • #13
                          Ok,

                          I have a page that have a form with a command and I what to pass the values of the command to another page.

                          Code:
                          <bean name="/UW0007Document.htm" class="com.uw.cigna.dm.controller.J002LetterController">
                          	<property name="sessionForm" value="true"/>
                              <property name="commandName" value="headerCommand"/>
                              <property name="commandClass" value="com.uw.cigna.dm.command.HeaderCommand"/>
                              <property name="headerService" ref="headerService"/> 
                              <property name="letterService" ref="letterService"/>   
                              <property name="bindOnNewForm" value="true"/>
                          </bean>
                          
                          <bean name="/UW0008LetterForm.htm" class="com.uw.cigna.dm.controller.J009LetterFormController">
                          	<property name="sessionForm" value="true"/>
                              <property name="commandName" value="headerCommand"/>
                              <property name="commandClass" value="com.uw.cigna.dm.command.HeaderCommand"/>
                              <property name="headerService" ref="headerService"/>
                              <property name="bindOnNewForm" value="true"/> 
                          </bean>
                          When I try to pass to the first page to the second page I have the problem.

                          Code:
                          org.apache.jasper.JasperException: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'headerCommand' available as request attribute
                          For this reason, I need to use a intermediate page.

                          Code:
                          model.addObject("url","UW0008LetterForm.htm");
                          model.setViewName("UW0000_Cigna_Succes");
                          In this page I redirect to the second page:

                          Code:
                          <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
                          <html>
                          <head>
                          </head>
                          <body>
                          <c:redirect url="${url}"/>
                          </body>
                          </html>

                          Comment


                          • #14
                            And the result is a empty request.

                            page1 -> page2 ERROR!!

                            page1 -> intermediate page -> page2 Empty request

                            Comment


                            • #15
                              A typical form using SimpleFormController has the following flow
                              1. Form is displayed to user (formView)
                              2. User inputs form values
                              3. User submits form
                              4. Input values are bound to command object and validation takes place
                              5. Application processes form values and does whatever business logic it needs to
                              6. Success page is displayed to user (successView)
                              Processing of the form should be done in the onSubmit() method.

                              Why do you want to pass the values to another page?

                              If this form is actually made up of different pages (like a wizard) then you can use AbstractWizardFormController or Spring Webflow.

                              If it is not and you want to pass the values from the form to another page (for whatever reason) then you should be able to return a redirect view and add the name/value pairs in the model to be bound to your new page.

                              So in your onsubmit method in your first form controller have

                              ModelAndView mav = ModelAndView("redirect:/newPage.htm");

                              And then add your form name/value pairs to the model

                              mav.addObject("headerCommand.name", "Sprang");
                              mav.addObject("headerCommand.location", "London");

                              return mav;

                              As you have bindOnNewForm set to true for your forms, they should bind these parameters as long as the paths are correct.

                              Comment

                              Working...
                              X