Pass loop variable from Freemarker template to Spring controller
<p>I am listing objects in a table in my view. I want to be able to edit an object using a button in the table. </p>

<pre><code>&lt;#list products as product&gt;
    &lt;tr&gt;
        &lt;td&gt;${product.productName}&lt;/td&gt;
        &lt;td&gt;${product.price}&lt;/td&gt;
        &lt;td&gt;${product.quantity}&lt;/td&gt;
        &lt;td&gt;
            &lt;form name="product" method="post" action="/product/edit"&gt;
                &lt;input type="submit" name="submit" value="Edit this product"/&gt;
            &lt;/form&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/#list&gt;
</code></pre>

<p>The object then should be passed to a controller method:</p>

<pre><code>@RequestMapping(value="/edit", method = RequestMethod.POST)
public ModelAndView edit(@ModelAttribute("product") Product product){
    ModelAndView mav = new ModelAndView("product/edit");
    mav.addObject("product", product);
    return mav;
}
</code></pre>

<p>However, the <code>product</code> obtained by the <code>edit</code> method is null. How do I fix this? I tried to bind the product inside form using the code below, but that did not work either.</p>

<pre><code>    &lt;form name="product" method="post" action="/product/edit"&gt;
        &lt;@spring.bind "product" /&gt;
        &lt;input type="hidden" name="${spring.status.expression}" value="${spring.status.value}"/&gt;
        &lt;input type="submit" name="submit" value="Edit this product"/&gt;
    &lt;/form&gt;
</code></pre>

<p>I want to use the POST method. </p>