Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamically binding lists with Spring's form tag
    primarykey
    data
    text
    <p>I have a command object <code>FaxForm</code> and it holds a list of <code>FaxStatus</code> objects inside a <code>faxStatusList</code> property. </p> <pre><code>public class FaxForm { private List&lt;FaxStatus&gt; faxStatusList; public void setFaxStatusList(List&lt;FaxStatus&gt; faxStatusList) { this.faxStatusList = faxStatusList; } public List&lt;FaxStatus&gt; getFaxStatusList() { return faxStatusList; } } </code></pre> <p>I initially had a JSP page that would bind the objects by performing the following:</p> <pre><code>&lt;c:forEach items="${esaFaxForm.faxStatusList}" var="item" varStatus="loop"&gt; &lt;tr class="tableAltBackground"&gt; &lt;td&gt; &lt;form:checkbox path="faxStatusList[${loop.index}].selected"/&gt; &lt;/td&gt; &lt;td&gt; &lt;form:select path="faxStatusList[${loop.index}].status" items="${esaFaxForm.statusOptions}" onchange="checkThisBox(this);"/&gt; &lt;/td&gt; &lt;td&gt; &lt;a href="${statusContUrl}?id=${item.id}&amp;status=${item.status}" onclick="openFaxWindow('${viewFaxUrl}?id=${item.id}', ${loop.index});"&gt;${item.name}&lt;/a&gt; &lt;form:hidden path="faxStatusList[${loop.index}].name"/&gt; &lt;/td&gt; &lt;td&gt; &lt;a href="${statusContUrl}?id=${item.id}&amp;status=${item.status}" onclick="openFaxWindow('${viewFaxUrl}?id=${item.id}', ${loop.index});"&gt;${item.id}&lt;/a&gt; &lt;form:hidden path="faxStatusList[${loop.index}].id"/&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/c:forEach&gt; </code></pre> <p>However, I am trying to figure out how I could do the binding without the forEach loop and index. The examples on the <a href="http://static.springsource.org/spring/docs/2.0.x/reference/mvc.html" rel="nofollow noreferrer">Spring</a> website show the binding by setting the path to the list name. Is there a way to bind the properties? I've tried this but it fails:</p> <pre><code>&lt;form:checkbox path="faxStatusList.faxStatus.selected"/&gt; &lt;form:select path="faxStatusList.faxStatus.status" items="${esaFaxForm.statusOptions}"/&gt; </code></pre> <p>The faxStatusList has a getter and setter method and the FaxStatus variables each have getter/setter properties. I get the error "Invalid property 'faxStatusList.faxStatus' of bean class..."</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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