0

I am developing a questionnaire application with spring MVC. I have the form with 30 questions and 30 radio buttons. When the user submit the form I have to get the user answers from the request I have three decision.

  1. Inside a loop call request.getParameter() 30 times

  2. :

    public class QuestionBank {
    
        private List<Question>  question;
    ....
    }
    
    
         <form:form action="question.html" modelAttribute="QuestionList" >
    
            <c:forEach items="${QuestionList.question}" var="q" varStatus="status">
             ...
                        <input type="radio" name="question[${status.index}].useranswer" value="1" />
                        <input type="radio" name="question[${status.index}].useranswer" value="2" />
                    ...
                    </div>
            </c:forEach>
    
                    <input type="submit" value="submit" />
             </form:form>
    

    process the list inside controller

  3. Use the Ajax submission (create a json format of answers)

From this three Which the recommended and fast processing ?

1
  • If speed is the goal, then I'd say AJAX is probably the fastest from the user's perspective as it doesn't require a full page reload. Second would be raw request and reading the parameters, as you don't have to wait for Spring to try to figure out how to build your objects. Last I'd say domain object and @ModelAttribute. This is all based on speculation, as I don't know internally the different paths Spring might possibly take.
    – CodeChimp
    Commented Oct 4, 2013 at 19:30

1 Answer 1

1

IMHO It's not a good idea that we search for the fastest way to doing something ! I think we should see what we want to do , the fastest way is relative to our issue ! If we just want to calculate the "time of processing" , it can not help us to find the better solution. Request , ajax or spring are 3 way to sending request to server. In your problem , I think it's better to use the object mapping with spring , because you are really sending a FORM and maybe you want to validate it and it's better spring do it for you, surely reloading all content of the page or a part of it is not the problem .

Not the answer you're looking for? Browse other questions tagged or ask your own question.