setting class and other attributes for spring form tag element
Solution 1
Ok I resolved some part of it. Looks like tags used inside form:input tag are different than regular html tags. All of them are listed here. For ex style
is cssStyle
.
So I change my code to
<form:input path="username" cssClass="text simpleTextField" maxlength="200" cssStyle="width:60%" disabled="true"/>
and now it works..
I still don't know how to populate value in this input. These seems no equivalent of value
keyword.
Solution 2
@Aniket You actually have an equivalent , consider in a case you have to populate the select
box with the values from the model attribute . You can make use of items
attribute.
For instance ,
<tr>
<td>City :</td>
<td><form:select path="city" items="${cityList}" /></td>
</tr>
It will generate the select with the the list of objects.
cityList
here refers the object that has been sent from the server side.
Hope this helps !
Aniket Thakur
Hi there, I love to code and learn new things! I firmly believe that "It is your attitude rather than your aptitude that determines your altitude" and "Nothing is impossible if you give it your sincere try". My Blog - Open Source For Geeks You can also view - My Playstore Apps and My Git repositories / Gists Youtube channel Chrome Plugin All the Best! Stay in touch :) (LinkedIn Profile)
Updated on August 21, 2022Comments
-
Aniket Thakur over 1 year
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 form:input spring tag. How can I achieve this? On inspecting the element it expands to be
<input id="username" type="text" value="" name="username"></input>
I need to populate its value as well as provide it with a class and additional attributes like width.
-
Aniket Thakur almost 10 yearsYes there are equivalent tags. Tx!