Passing hidden fields within a form

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Passing hidden fields within a form

pucadev
Hi,

I am having issues passing hidden fields to my controller.
In my html below the parameter ${field} equals InvestmentChoice
This class has a member called funds, which is a list:
   List<Fund> funds
The percentage value from my form gets passed successfully to the controller but not the hidden fields

Any ideas on how I can resolve this ?

Below is a sample from my form:

<div th:each="fund, rowStat : ${investmentfunds}">
        <div th:if="${fund.group == fundGroup}">
                <div class="col-sm-3">
                        <label th:text="${fund.name}">Fund</label>
                </div>
                <div class="col-sm-2">
                        <div class="input-group">
                                <input type="hidden" name="tab5_fundid"
                                        th:field="*{__${field}__.funds[__${rowStat.index}__].id}" />

                                <input type="hidden" name="tab5_fundname"
                                        th:field="*{__${field}__.funds[__${rowStat.index}__].name}" />

                                <input type="text" name="tab5_fundpercentage"
                                        class="form-control" placeholder=""
                                        th:field="*{__${field}__.funds[__${rowStat.index}__].percentage}" />
                                %
                        </div>
                </div>
        </div>
</div>

Java class for fund

public class Fund {

        private long id;

        private String group;

        private String name;

        private float percentage;

      /*   Getter / setters */
}

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Passing hidden fields within a form

danielfernandez
Administrator
Could you have a look at the result of rendering that fragment of your page and seeing the source code from the browser? That will allow you to determine whether those <input type="hidden" /> fields look like they should.

If the hidden fields look good at the browser's source code viewer, then it is some kind of configuration problem at Spring MVC. But if not, we will be able to better determine what can be happening.
Reply | Threaded
Open this post in threaded view
|

Re: Passing hidden fields within a form

pucadev
If input type for id and type are set to text then all works fine. However, it fails to pass values when type set to hidden

Here is the rendered html:

<div class="form-horizontal" role="form">
        <div class="form-group">
                <div>
                        <div>
                                <div class="col-sm-3">
                                        <label>Fund 1</label>
                                </div>
                                <div class="col-sm-2">
                                        <div class="input-group">
                                                <input type="hidden" name="investmentChoice.funds[0].id" id="investmentChoice.funds0.id" value="0" />                                               
                                                <input type="hidden" name="investmentChoice.funds[0].name" id="investmentChoice.funds0.name" value="" />
                                                <input type="text" name="investmentChoice.funds[0].percentage" class="form-control" placeholder="" id="investmentChoice.funds0.percentage" value="0.0" />
                                        %
                                                </div>
                                </div>
                        </div>
                </div>
                <div>
                        <div>
                                <div class="col-sm-3">
                                        <label>Fund 2</label>
                                </div>
                                <div class="col-sm-2">
                                        <div class="input-group">
                                                <input type="hidden" name="investmentChoice.funds[1].id" id="investmentChoice.funds1.id" value="0" />                                               
                                                <input type="hidden" name="investmentChoice.funds[1].name" id="investmentChoice.funds1.name" value="" />
                                                <input type="text" name="investmentChoice.funds[1].percentage" class="form-control" placeholder="" id="investmentChoice.funds1.percentage" value="0.0" />
                                        %
                                                </div>
                                </div>
                        </div>
                </div>
        </div>
</div>
Reply | Threaded
Open this post in threaded view
|

Re: Passing hidden fields within a form

danielfernandez
Administrator
Your HTML looks quite OK to me. I would say Thymeleaf is doing its job correctly. IMHO your problem belongs more to the controller side (i.e., your Spring MVC configuration)