Skip to content

Commit 2dae4d8

Browse files
committed
Deprecated FormTag's "commandName" in favor of "modelAttribute"
Issue: SPR-14094
1 parent 26bbb6e commit 2dae4d8

File tree

4 files changed

+12
-17
lines changed

4 files changed

+12
-17
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/FormTag.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -147,15 +147,19 @@ protected String getModelAttribute() {
147147
* Set the name of the form attribute in the model.
148148
* <p>May be a runtime expression.
149149
* @see #setModelAttribute
150+
* @deprecated as of Spring 4.3, in favor of {@link #setModelAttribute}
150151
*/
152+
@Deprecated
151153
public void setCommandName(String commandName) {
152154
this.modelAttribute = commandName;
153155
}
154156

155157
/**
156158
* Get the name of the form attribute in the model.
157159
* @see #getModelAttribute
160+
* @deprecated as of Spring 4.3, in favor of {@link #getModelAttribute}
158161
*/
162+
@Deprecated
159163
protected String getCommandName() {
160164
return this.modelAttribute;
161165
}

spring-webmvc/src/main/resources/META-INF/spring-form.tld

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
version="2.0">
66

77
<description>Spring Framework JSP Form Tag Library</description>
8-
<tlib-version>4.0</tlib-version>
8+
<tlib-version>4.3</tlib-version>
99
<short-name>form</short-name>
1010
<uri>http://www.springframework.org/tags/form</uri>
1111

@@ -131,8 +131,7 @@
131131
<rtexprvalue>true</rtexprvalue>
132132
</attribute>
133133
<attribute>
134-
<description>Name of the model attribute under which the form object is exposed.
135-
Defaults to 'command'.</description>
134+
<description>DEPRECATED: Use "modelAttribute" instead.</description>
136135
<name>commandName</name>
137136
<required>false</required>
138137
<rtexprvalue>true</rtexprvalue>

src/asciidoc/appx-spring-form-tld.adoc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,6 @@ Renders an HTML 'form' tag and exposes a binding path to inner tags for binding.
528528
| true
529529
| HTML Required Attribute
530530

531-
| commandName
532-
| false
533-
| true
534-
| Name of the model attribute under which the form object is exposed. Defaults to 'command'.
535-
536531
| cssClass
537532
| false
538533
| true

src/asciidoc/web-view.adoc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,10 @@ directly, the files are called spring.vm / spring.ftl and are in the packages
292292

293293
[[view-simple-binding]]
294294
==== Simple binding
295-
In your html forms (vm / ftl templates) that act as the 'formView' for a Spring form
295+
In your HTML forms (vm / ftl templates) which act as a form view for a Spring MVC
296296
controller, you can use code similar to the following to bind to field values and
297297
display error messages for each input field in similar fashion to the JSP equivalent.
298-
Note that the name of the command object is "command" by default, but can be overridden
299-
in your MVC configuration by setting the 'commandName' bean property on your form
300-
controller. Example code is shown below for the `personFormV` and `personFormF` views
301-
configured earlier;
298+
Example code is shown below for the `personFormV`/`personFormF` views configured earlier:
302299

303300
[source,xml,indent=0]
304301
[subs="verbatim,quotes"]
@@ -308,7 +305,7 @@ configured earlier;
308305
...
309306
<form action="" method="POST">
310307
Name:
311-
#springBind( "command.name" )
308+
#springBind("myModelObject.name")
312309
<input type="text"
313310
name="${status.expression}"
314311
value="$!status.value"/><br>
@@ -331,7 +328,7 @@ configured earlier;
331328
...
332329
<form action="" method="POST">
333330
Name:
334-
<@spring.bind "command.name"/>
331+
<@spring.bind "myModelObject.name"/>
335332
<input type="text"
336333
name="${spring.status.expression}"
337334
value="${spring.status.value?default("")}"/><br>
@@ -818,7 +815,7 @@ The preceding JSP assumes that the variable name of the form backing object is
818815
[source,xml,indent=0]
819816
[subs="verbatim,quotes"]
820817
----
821-
<form:form commandName="user">
818+
<form:form modelAttribute="user">
822819
<table>
823820
<tr>
824821
<td>First Name:</td>

0 commit comments

Comments
 (0)