Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 817
Kshitiz Sharma Avatar asked Feb 06 '14 04:02

Kshitiz Sharma


People also ask

What is the purpose of label tag in HTML?

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.

What is spring form tag?

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.

What is @TAG in spring boot?

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.

What is Spring MVC Jstl?

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.


2 Answers

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

like image 154
M. Deinum Avatar answered Sep 30 '22 07:09

M. Deinum


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.

like image 24
K. hervey Avatar answered Sep 30 '22 06:09

K. hervey