Announcement Announcement Module
Collapse
No announcement yet.
SimpleFormController and Back button Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SimpleFormController and Back button

    Hi,

    I am using SimpleFormController for my search form. After submit form my success view is searchResult. Now If I use browser back button to go back to my search form, the form has been resetted to the default values instead of retaining the value which I entered.

    I am new to spring and I think this is quite a basic question and has been resolved many times. I googled it alot but cannot able to find answer. So please help me guys.

  • #2
    There is no consent between browsers on keeping form data. Some keep it and let you choose from dropdowns, some auto-fill it with the last version, some don't keep it at all.
    What you can do is pre-populate the fields when responding to the browser. Using setSessionForm(true) in your scenario might be the solution.

    Comment


    • #3
      SimpleFormController and Back button

      Thanks for your reply. But still if I use setSessionForm(true) it is calling createCommand() which creates a new fromBean instance and initialize it with the default values.

      I did a work around with overriding the formBackingObject. I put the SearchFormBean formBean; as global to the my SearchController and while overriding onSubmit I am initializing it with;
      formBean = (SearchFormBean) command;

      In the formBackingObject I am just testing it

      if(formBean == null){
      return createCommand() // This will create a new SearchFormBean instance

      } else {
      return formBean;


      I am not sure this is the best way to solve the problem.

      Comment


      • #4
        The command would have been created anyway. The difference is if you set sessionForm to true the command will only be created on GET requests. To keep the command even for GET requests either override isFormSubmission and return true, or keep the command in session yourself (you must retrieve it from session in formBackingObject).

        What do you mean by "global" ? Did you refer to "static" ?
        Please remember that Controllers are application-level beans (not session). If you use static then all session will share the same command, so if one user logs in from China and enters some data in the form, another user from Spain will see the data entered by the other user.

        Comment


        • #5
          SimpleFormController and Back button

          Thanks for the reply and very useful suggestion.
          First of all I am really sorry not to reply soon as I was busy with a production problem.
          Here global means global to the class. What I have seen in different examples, normally formbeans are created with in the scope of the method e.g onSubmit.

          SearchFormBean formBean = (SearchFormBean) command;

          I just move the variable declaration out of the method.

          Comment

          Working...
          X