Announcement Announcement Module
Collapse
No announcement yet.
How to avoid binding of Query Parameters? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to avoid binding of Query Parameters?

    Spring MVC, by default binds the Query Parameters as well. We have a problem because of this feature. Whenever the url of our application is accessed with a query parameter matching with one of the binded form attributes, Spring MVC automatically binds the value of the query parameter.
    Is it possible to avoid this?

    Meaning we want a feature like
    if(request == GET)
    don't bind querystring parameters to my command
    if(request == POST)
    bind ONLY post parametes to my commnd

    Thanks in advance,
    Srivathsa

  • #2
    I don't think the HttpServletRequest distinquishes between parameters specified by GET and POST.

    Not sure whether the actual HTTP spec does either....

    So no, I don't think you can

    Comment


    • #3
      Originally posted by Srivathsa
      Meaning we want a feature like
      if(request == GET)
      don't bind querystring parameters to my command
      if(request == POST)
      bind ONLY post parametes to my commnd
      Isn't that the default behavior of Spring's form controllers? I thought Spring MVC would bind during GET only when bindOnNewForm is set to true.

      Comment


      • #4
        Originally posted by manifoldronin
        Isn't that the default behavior of Spring's form controllers? I thought Spring MVC would bind during GET only when bindOnNewForm is set to true.
        Almost

        The default behaviour of SimpleFormController is to only bind on POSTs, but the troublesome part is distinquishing between parameters specified in the URL and those submitted as part of the POST.

        For example, if I submit a form which contains an input element of name="param2" and value="value2" to the URL myForm?param1=value1 then both param1 and param2 will be bound. The OP only wants param2 bound, param1 should be ignored.

        At least that is my understanding of the OP question.

        Comment


        • #5
          Originally posted by yatesco
          At least that is my understanding of the OP question.
          You are right. Guess I was fooled by OP's "if (request==GET)" thing.

          Comment


          • #6
            Finally, after some investigation, we were able to find an alternative.

            We were using Wizard Form Controller. In initBinder(HttpServletRequest request, ServletRequestDataBinder binder)

            from the request object, we were able to differentiate GET requests from POST requests and restrict the parameters that needs to be binded to a limited array of the parameters (param1 and param2) for which binding needs to be restricted.

            if("GET".equalsIgnoreCase(request.getMethod())) {
            String check [] = {"param1", "param2"};
            binder.setAllowedFields(check);
            }
            Thanks to yatesco's post on "AbstractWizardFormController and GET parameter binding "
            http://forum.springframework.org/showthread.php?t=17370

            Best Regards,
            Srivathsa

            Comment

            Working...
            X