Struggling with Forms in Spring

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

Struggling with Forms in Spring

Martin
Hi,

This chap seems to create huge problems and causes the template to crash w/in Thymeleaf. Any suggestions?

Cannot seem to figure out why it's not liking the static list of options; Guessing I *need* to have a th:value in there somewhere ja?

                <form id="applicationform" method="PUT" action="#"
                   th:object="${configuration}" th:action="@{/configuration}" >
                  <legend>Defaults</legend>
                  <fieldset class="control-group">
                    <label for="select01" class="control-label">Default Number of Indicators</label>
                    <div class="controls">
                      <select name="select01" th:field="*{defaultNumberOfIndicators}">
                        <option value="1">1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5">5</option>
                      </select>
                    </div>
                  </fieldset>
                  <fieldset class="control-group">
                    <label for="select02" class="control-label">Default Number of Weightings</label>
                    <div class="controls">
                      <select name="select02"  th:field="*{defaultNumberOfWeightings}">
                        <option value="1">1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5">6</option>
                        <option value="6">6</option>
                        <option value="7">7</option>
                        <option value="8">8</option>
                        <option value="9">9</option>
                        <option value="10">10</option>
                      </select>
                    </div>
                  </fieldset>
                </form>
Reply | Threaded
Open this post in threaded view
|

Re: Struggling with Forms in Spring

Martin
Hi (again).

Pay me no mind -- it's solved I think. Used:


                      <select name="select01" th:field="*{defaultNumberOfIndicators}">
                        <option th:each="val : ${#numbers.sequence(1,5)}"
                                th:value="${val}"
                                th:text="${val}"></option>
                        <option value="1" th:remove="all">1</option>
                        <option value="2" th:remove="all">2</option>
                        <option value="3" th:remove="all">3</option>
                        <option value="4" th:remove="all">4</option>
                        <option value="5" th:remove="all">5</option>
                      </select>


Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Struggling with Forms in Spring

danielfernandez
Administrator

Just one thing:

Please, pay attention to the fact that Thymeleaf (mimic'ing Spring MVC's JSP tags behaviour) will change the "name" attribute of your select there and will set it to the name of the property in the Command bean, thus breaking your "label for" tags.

Regards,
Daniel.
Reply | Threaded
Open this post in threaded view
|

Re: Struggling with Forms in Spring

Martin
Excellent sir,
Took me a little while to figure that out -- thanks for the heads up.