Installation class and other attributes for the spring form tag element

I have the following page and it does not load

<form:form action="/test.htm"  method="post" commandName="demoForm" >

<div id="testSection" style="margin-top: 1.5%;margin-left: 3.5%;">

    <span class="test-container">
            <label>UserName</label>
            <span class="test-container-right">
                <form:input path="username" value="${UNAME}"  class="text simpleTextField" maxlength="200" style="width:60%" disabled/>
            </span>
    </span>

    <span style="width:auto; padding-left: 30%; padding-bottom: 4%; text-align:center; float:right; clear:both;">
        <input type="submit" class="btn" style="width:auto;" value="Save" />
    </span>     

</div>

</form:form>

but when i change it to

...
<span class="test-container-right">
        <form:input path="username" />
</span>
...

It works and loads correctly. Why am I not allowed to set html properties for the form: input spring. How can i achieve this? When checking an item, it expands to

<input id="username" type="text" value="" name="username"></input>

I need to fill in its value, and also provide it with a class and additional attributes such as width.

+4
source share
2 answers

OK, I allowed part of it. It seems the tags used inside the form: the input tag is different from regular html tags. All are listed here . For ex styleis cssStyle.

,

<form:input path="username" cssClass="text simpleTextField" maxlength="200" cssStyle="width:60%" disabled="true"/>

.

, . value.

+4

@Aniket , , select model. items.

,

     <tr>
      <td>City :</td>
      <td><form:select path="city" items="${cityList}" /></td>
     </tr>

. cityList , .

, !

+1

Source: https://habr.com/ru/post/1547885/


All Articles