Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC: Difference between spring:bind and form:form

I am looking to find out the difference between the spring:bind and form:form tag libraries when submitting a form.

A snippet of my JSP is as follows:

<form:form modelAttribute="testRulesForm">
....
<td>
    <form:checkbox path="rules[${counter.index}].isActive" value="rules[${counter.index}].isActive"/>
</td>
<td>
    <form:select path="rules[${counter.index}].leftCondition.name">
        <form:options items="${testRulesForm.ruleAttributes}" itemLabel="name" itemValue="name" />
    </form:select>
</td>
<td>
    <form:select path="rules[${counter.index}].operator">
        <form:options itemLabel="operator" itemValue="operator" />
    </form:select>
</td>
....

Seeing as I have my path variable specified and this will be bound to my modelAttribute, does this mean that I do not need spring:bind?

Thanks

like image 966
DJ180 Avatar asked Dec 21 '11 14:12

DJ180


People also ask

What is form binding in Spring MVC?

Form Handling Support in Spring MVC Model: basically a POJO (Plain Old Java Object) class is created to bind form fields with properties of the object. This object will be put into the model (model object).

What does Spring bind do?

The spring:bind tag provides you with support for evaluation of the status of a certain bean or bean property.

Which are the correct options in Spring MVC that are used to bind the model class properties to form properties?

One of the most important Spring MVC annotations is the @ModelAttribute annotation. @ModelAttribute is an annotation that binds a method parameter or method return value to a named model attribute, and then exposes it to a web view.

What is the use of Spring form?

A springform pan is a round cake pan that features a removable bottom and sides. The sides are held together with an interlocking band that can be opened and removed once your baked good is out of the oven, leaving your cake on the base.


1 Answers

Normally you don't need to use <spring:bind> if you already use form taglib.

They do basically the same with respect to model attributes, but tags from form taglib also generate HTML form markup, whereas with <spring:bind> you need to generate markup yourself.

The following code with form tags:

<form:form modelAttribute = "foo">
    <form:input path = "bar" />
</form:form>

is similar to the following code with <spring:bind>:

<spring:bind path = "foo">
    <form method = "get">
        <spring:bind path = "bar">
            <input name = "bar" value = "${status.displayValue}" />
        </spring:bind>
    </form>
</spring:bind>

<spring:bind> is useful when you need something customized, that cannot be achieved by form taglib.

like image 170
axtavt Avatar answered Oct 06 '22 23:10

axtavt