when submitting a form

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

when submitting a form

Kay
Hi, I have a simple question about a form usage.

in HTML form, I set <input type="text" th:field="*{username}" disabled="true"/> so that username cannot be modified by the form input.

however, when the controller gets UserDTO of the form, the username field is always null.
without disabled="true" attributes, it has a value.

I would make disable the input form but need to get the value of it
Is there any easy way to do this

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

Re: when submitting a form

eiryu
try this

<input type="text" th:field="*{username}" readonly="readonly"/>
Kay
Reply | Threaded
Open this post in threaded view
|

Re: when submitting a form

Kay
that works fine! Thank you!!
Reply | Threaded
Open this post in threaded view
|

Re: when submitting a form

blandger
Hi all.
I didn't want to open new thread, so asking here.

How to create following makeup from JSP code (Spring MVC + Flow) for displaying error message ??
                            <div class="four columns">
                                <form:label path="email">
                                    <spring:message code="register.event.step01.page.label.email"/>
                                    <br/><form:errors path="email" cssClass="alert label" />
                                </form:label>
                            </div>
                            <div class="six columns end">
                                <form:input path="email" maxlength="50" disabled="${loggedIn}"/>
                            </div>

I came to following code, but it work not quite well, as expected, because '<errors path="email"...' obviously doesn't work and I don't know how to make it correctly.

<quote>
                        <div class="four columns">
                            <label for="email" th:text="#{register.event.step01.page.label.email}">
                                <br/><errors path="email" cssClass="alert label" />
                            </label>
                        </div>
                        <div class="six columns end">
                            <input name="email" type="text" th:field="*{email}" maxlength="50" th:disabled="! ${#authentication}"/>
                        </div>


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

Re: when submitting a form

danielfernandez
Administrator

Hi,

There is a "#fields.errors(path)" utility object you can use for obtaining the list of form errors and iterate it. See an example here: https://github.com/thymeleaf/thymeleafexamples-stsm/blob/thymeleafexamples-stsm-20121220/src/main/webapp/WEB-INF/templates/seedstartermng.html

Regards,
Daniel.