Kshitiz Sharma Kshitiz Sharma - 1 year ago 58
Java Question

What is the advantage of form:label tag in Spring?

<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 <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