<form:label path="company">Enter company name:</form:label>
Renders -
<label for="company">Enter company name:</label>
Why shouldn't I directly use the HTML tag which is more concise?
The <label> tag in HTML is used to provide a usability improvement for mouse users i.e, if a user clicks on the text within the <label> element, it toggles the control. The <label> tag defines the label for <button>, <input>, <meter>, <output>, <progress>, <select>, or <textarea> element.
Spring tag Library The 'form' tag renders an HTML 'form' tag. It exposes a binding path to inner tags for binding the data entered. It puts the command object in the PageContext so that the command object can be accessed by all the inner tags.
The Spring MVC form tags are the configurable and reusable building blocks for a web page. These tags provide JSP, an easy way to develop, read and maintain. The Spring MVC form tags can be seen as data binding-aware tags that can automatically set data to Java object/bean and also retrieve from it.
JavaServer Pages Tag Library (JSTL) is a set of tags that can be used for implementing some common operations such as looping, conditional formatting, and others. Here we will be discussing how to use the Maven build tool to add JSTL support to a Spring MVC application.
The <form:label />
tag has access to the underlying model and binding results and as such can, on error, use another style class.
<form:label cssClass="title" cssErrorClass="title error" path="company" />
The code above would, in case of an error, render differently than the normal case. Of course you could also do this without the form tag but that would mean you need to include some logic into your pages, which in general isn't advised.
For all the properties see the reference guide
I really like using form:xxxx instead of the more traditional tags.
However, it seems to work best with PUT requests where I am modifying something, and maybe DELETE. With POST where everything is new, I tend to end up using the traditional tags.
It does link the human readable to the value being sent for automated readers, but both can do that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With