Results 1 to 5 of 5

Thread: Form modification based on user's actions

  1. #1

    Default Form modification based on user's actions

    I'm using Spring 3 and I would like to make a form, which fields are added based on user's actions. For example, a certain fields appear when user clicks the radiobutton, or a new text field appears when user clicks a buttonlink. This is new to me. Can anyone advise me how to do this? Maybe with childpages? Is there a code example?

  2. #2
    Join Date
    Aug 2008
    Posts
    105

    Default

    I think that you should use javascript on your form and hide/show a specific input..

  3. #3

    Default

    But how about if I use c:if-clauses on a view to determine which parts of the form should be shown and refresh the page?

  4. #4
    Join Date
    Mar 2010
    Location
    Boston, MA
    Posts
    316

    Default

    If the decision (of what to show and what not to) is made on the server side and if you don't want to refresh the entire page, you can use Spring JS and Ajax view resolver http://static.springsource.org/sprin...l/ch11s05.html.

    If the decision can be made on the client side, go with javascript.

    If the decision has to be made on the server side and you are OK with refreshing the page, use JSTL/EL to show hide specific sections of the page.

  5. #5

    Default

    I managed to come up with a solution something like this

    Code:
     @RequestMapping ("/choice1")
        public String one(@ModelAttribute("form") Form form) {
            form.setApptype(1);
            return "index";
     }
       @RequestMapping ("/choice2")
        public String two(@ModelAttribute("form") Form form) {
            form.setApptype(2);
    return "index";
    I don't actually have the views called choice1 and choice2, but the mapping works when I link to choice1.html and choice2.html from my radiobutton's onClick attribute. These methods call my index page again, which show the fields that are supposed to show, because I have <c:if>-clauses based on apptype value in my index.jsp.

    Now my problem is, that I cannot get to my OnSubmit-method after choosing the radiobutton! I get the index view when clicking the submit button over and over again! Is there any easy way to solve this?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •