Skip to content

Commit ed06a6d

Browse files
committed
Convert SimpleFormController example to @controller in reference manual
This change is necessary since the SimpleFormController class no longer exists.
1 parent afa799b commit ed06a6d

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/docs/asciidoc/core/core-validation.adoc

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,8 @@ See also the `org.springframework.beans.support.ResourceEditorRegistrar` for an
792792
`PropertyEditorRegistrar` implementation. Notice how in its implementation of the
793793
`registerCustomEditors(..)` method, it creates new instances of each property editor.
794794

795-
The next example shows how to configure a `CustomEditorConfigurer` and inject an instance of our
796-
`CustomPropertyEditorRegistrar` into it:
795+
The next example shows how to configure a `CustomEditorConfigurer` and inject an instance
796+
of our `CustomPropertyEditorRegistrar` into it:
797797

798798
[source,xml,indent=0,subs="verbatim,quotes"]
799799
----
@@ -809,50 +809,51 @@ The next example shows how to configure a `CustomEditorConfigurer` and inject an
809809
class="com.foo.editors.spring.CustomPropertyEditorRegistrar"/>
810810
----
811811

812-
Finally (and in a bit of a departure from the focus of this chapter for those of you
813-
using <<web.adoc#mvc, Spring's MVC web framework>>), using `PropertyEditorRegistrars` in
814-
conjunction with data-binding `Controllers` (such as `SimpleFormController`) can be very
815-
convenient. The following example uses a `PropertyEditorRegistrar` in the
816-
implementation of an `initBinder(..)` method:
812+
Finally (and in a bit of a departure from the focus of this chapter) for those of you
813+
using <<web.adoc#mvc, Spring's MVC web framework>>, using a `PropertyEditorRegistrar` in
814+
conjunction with data-binding web controllers can be very convenient. The following
815+
example uses a `PropertyEditorRegistrar` in the implementation of an `@InitBinder` method:
817816

818817
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
819818
.Java
820819
----
821-
public final class RegisterUserController extends SimpleFormController {
820+
@Controller
821+
public class RegisterUserController {
822822
823823
private final PropertyEditorRegistrar customPropertyEditorRegistrar;
824824
825-
public RegisterUserController(PropertyEditorRegistrar propertyEditorRegistrar) {
825+
RegisterUserController(PropertyEditorRegistrar propertyEditorRegistrar) {
826826
this.customPropertyEditorRegistrar = propertyEditorRegistrar;
827827
}
828828
829-
protected void initBinder(HttpServletRequest request,
830-
ServletRequestDataBinder binder) throws Exception {
829+
@InitBinder
830+
void initBinder(WebDataBinder binder) {
831831
this.customPropertyEditorRegistrar.registerCustomEditors(binder);
832832
}
833833
834-
// other methods to do with registering a User
834+
// other methods related to registering a User
835835
}
836836
----
837837
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
838838
.Kotlin
839839
----
840+
@Controller
840841
class RegisterUserController(
841-
private val customPropertyEditorRegistrar: PropertyEditorRegistrar) : SimpleFormController() {
842+
private val customPropertyEditorRegistrar: PropertyEditorRegistrar) {
842843
843-
protected fun initBinder(request: HttpServletRequest,
844-
binder: ServletRequestDataBinder) {
844+
@InitBinder
845+
fun initBinder(binder: WebDataBinder) {
845846
this.customPropertyEditorRegistrar.registerCustomEditors(binder)
846847
}
847848
848-
// other methods to do with registering a User
849+
// other methods related to registering a User
849850
}
850851
----
851852

852853
This style of `PropertyEditor` registration can lead to concise code (the implementation
853-
of `initBinder(..)` is only one line long) and lets common `PropertyEditor`
854-
registration code be encapsulated in a class and then shared amongst as many
855-
`Controllers` as needed.
854+
of the `@InitBinder` method is only one line long) and lets common `PropertyEditor`
855+
registration code be encapsulated in a class and then shared amongst as many controllers
856+
as needed.
856857

857858

858859

0 commit comments

Comments
 (0)