Announcement Announcement Module
Collapse
No announcement yet.
How do I use the get method on forms Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I use the get method on forms

    Hello,

    I'm new to Spring. I need to develop a search form with the get method so people can bookmark their search result. However I could not find any usefull information on how to do this.

    I tried different different onSubmit signature without any success, although they all work with the post method.

    Could someone point me to resources on using the get method on forms.

    Thanks
    Yves

  • #2
    just put the "method" attribute into your <form:form> tag like so:

    <form:form method="get">

    </form:form>
    Of course you will want to put the other stuff too like the command object or whatever.

    Comment


    • #3
      I don't think the above reply answered your question completely. In addition to modifying the method on your form, as correctly indicated above, you'll need to make changes to your controller too.

      The default behavior of SimpleFormController is that a form "submit" equates to a POST request for the URL. You simply need to override this behavior in your controller by overriding the isFormSubmission method. The tricky bit about equatinga form "submit" in this way is that you need to be careful that the user's initial "GET" request isn't processed as a form submit. Generally this is done by looking for a particular request parameter or bean content indicating that the search button was pressed. For example, if you have JSP as such:
      HTML Code:
       <input name="search" value="Go!" />
      Your isFormSubmission method might look like this:
      Code:
          protected boolean isFormSubmission(HttpServletRequest request)
          {
              // this form is implemented as a GET, so look for the "search" URL parameter
              if(request.getParameter("search") != null) {
                  return true;
              } else {
                  return false;
              }
          }
      Obviously you would change the name of the parameter as befits your form. Makes sense?

      Comment


      • #4
        Thanks. It now works! in fact, I was closed. I just needed to test the search param button in the isSubmissionForm.

        It seems that the spring form tag does not make any difference over the html one. What functionality does the form tag add?

        Comment


        • #5
          Originally posted by Yves View Post
          Thanks. It now works! in fact, I was closed. I just needed to test the search param button in the isSubmissionForm.

          It seems that the spring form tag does not make any difference over the html one. What functionality does the form tag add?
          The form tag by itself is probably not all that helpful for you, however if you are taking advantage of the other Spring form tags (form:select, etc) it's required. Take a look at the Spring 2.0 form taglib docs for more information.

          Comment

          Working...
          X