Reputation: 2300
I have to 4 objects, Group, sections and Questions and their options. Every Group has different Sections and Sections have Multiple Questions and Questions have options. Now I have to design form input system so that every group and sections can be covered up step by step. I’m doing all this in spring mvc.
Can you tell me a way, how can I solve this problem?
Upvotes: 3
Views: 2241
Reputation: 10405
You can surely do that in Spring MVC thanks to easy list binding.
Spring MVC allows a big lot of freedom, so basically if you only use this framework, you will have to come up with a solution from scratch.
Here is a use case and a solution. It is a bit tough to implement, as it is from scratch. Feel free to adapt it to your specific needs, add whatever fancy UI framework you want, but you should get a general idea. You can skip to part III for a quick answer.
Let's say you want to create/edit a group in one single page :
I. Page design :
II. Code design :
List<Section> sections
attribute, the Section object has a List<Questions> questions
attribute, etc.III. The magic : binding the JSP form with the Java controller :
In the page you'll have a <form:form commandName="group">
, and in the controller methods parameters you'll have a @ModelAttribute("group") Group group
.
Now, to submit the name of the very first option, you would have this in the JSP :
<form:input path="sections[0].questions[0].options[0].name" />
(or the equivalent in html generated by some javascript).
Upvotes: 2