Announcement Announcement Module
Collapse
No announcement yet.
Looking for an example of isFormChangeRequest Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Looking for an example of isFormChangeRequest

    I'm struggling a bit with how to implement isFormChangeRequest. Has anyone put this method to good use?

    Here's the situation we're trying to handle. We've got several forms that are fairly dynamic. The user adds fields to the form as they edit the data.

    For example one of these forms is editing a boolean logic statement, so the user is adding additional OR and AND clauses to the the form as they go, and then finally submitting the whole thing to save.

    This seems like the place where isFormChangeRequest would come into play. I want to submit the form, but not do validation and return to the form view with the additional fields added plus with appropriate extra reference data.

    I'm trying to decide what the best way is to determine that this is a formChangeRequest or not.

  • #2
    What I think is a good practise here is to give a name to your submit buttons and to check the presence of those names in the request to know what submit button was used to send the request. It avoids javascript and is easy and robust to set up.
    for instance : <input type='submit' name='field-add' value='add a condition field'>
    and in the isFormChangeRequest method body : return request.getParameter("field-add") != null

    HTH

    Comment


    • #3
      Thanks for the feedback

      Thanks ojolly,

      Thats the route I was looking at going. however in some of our UI designs we've been using links instead of buttons. I may have to do something with a hidden field, or come up with some fancy CSS that makes a submit button look like a link.

      Has anyone done many dynamic forms like I'm talking about. Every example I ever find is the typical shopping cart app that never seems to match the complexity of the apps we're building.

      Comment


      • #4
        I'm also curious to know what the proper use of isFormChangeRequest() is. I would like to use this to make changes to my form, but isFormChangeRequest() accepts only the request object and returns boolean. This sounds like a good place to check for the request parameter indicating a change, but doesn't seem like the right place to do the actual changes.

        It would be nice if SimpleFormController had an empty method processFormChangeRequest called from processFormSubmission that could be overridden by implementing classes to peform the changes.

        Code:
        ...
        protected ModelAndView processFormSubmission&#40;HttpServletRequest request,
                HttpServletResponse response, Object command, BindException errors&#41;
                throws Exception &#123;
            if &#40;errors.hasErrors&#40;&#41;&#41; &#123;
                if &#40;logger.isDebugEnabled&#40;&#41;&#41; &#123;
                    logger.debug&#40;"Data binding errors&#58; " + errors.getErrorCount&#40;&#41;&#41;;
                &#125;
                return showForm&#40;request, response, errors&#41;;
            &#125;
            else if &#40;isFormChangeRequest&#40;request&#41;&#41; &#123;
                processFormChangeRequest&#40;request, response, command, errors&#41;;
                return showForm&#40;request, response, errors&#41;;
            &#125;
            else &#123;
                logger.debug&#40;"No errors -> processing submit"&#41;;
                return onSubmit&#40;request, response, command, errors&#41;;
            &#125;
        &#125;
        
        protected void processFormChangeRequest&#40;HttpServletRequest request, 
                HttpServletResponse response, Object command, BindException errors&#41;
                throws Exception &#123;
        &#125;
        ...

        Comment

        Working...
        X