Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding multiple objects in a Spring form
    text
    copied!<p>I have problems with getting my JSP view right. What I intend to do is to send a List that contains questions and each question object is a text field and a List with alternatives.</p> <p>My intention is to be able to edit multiple questions (both to be able to edit the text/name of the question and edit the containing alternatives).</p> <p>My backing object is now sending an List question.</p> <p>Here is my JSP which are failing with invalid property of bean class.</p> <pre><code> &lt;form:form commandName="question"&gt; &lt;form:errors path="*"&gt; &lt;fieldset class="stdframe"&gt; &lt;legend&gt;Question&lt;/legend&gt; &lt;/fieldset&gt; &lt;/form:errors&gt; &lt;div class="stdframe"&gt; &lt;c:forEach var="q" items = "${question}" varStatus = "s"&gt; &lt;p&gt;&lt;b&gt;Question:&lt;/b&gt;&lt;/p&gt; &lt;p&gt;&lt;form:input size="67" path="${q.text}"/&gt;&lt;/p&gt; &lt;br/&gt; ${q.text} &lt;ul&gt; &lt;c:forEach var="alternative" items = "${q.alternatives}" varStatus = "t"&gt; ${alternative.text} &lt;li&gt;&lt;form:input path = "${alternative[$t.index].text}" /&gt;&lt;/li&gt; &lt;/c:forEach&gt; &lt;/ul&gt; &lt;br/&gt; &lt;/c:forEach&gt; &lt;input type="submit" class="submit" value="Save" /&gt; &lt;input type="button" class="button" onClick="back()" value="Back"/&gt; &lt;/div&gt; &lt;/form:form&gt; </code></pre> <p>I have tried both <code>${q.text}</code> and <code>${q[$s.index].text}</code>. When I just print <code>${q.text}</code> it shows the correct text for the question object. Same goes for alternative.</p> <p>What can I do to correctly bind the form to the objects?</p> <p>In addition when I store an object which contains a list of other object, will the list be stored itself in the database? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload