From ac7d428a627e6dabbde500266eaeed4670e37bfb Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Thu, 17 Nov 2022 15:54:17 +0100 Subject: [PATCH] Work around code example callout bug This commit adds callouts to two sets of Java/Kotlin code examples in the @ModelAttribute section for Web MVC in order to work around the "Code example has callout from a different code example" bug. This also aligns the Web MVC examples with the WebFlux examples. As a side note, the bug can also be seen in the WebFlux documentation if the callouts are removed from the first Java/Kotlin examples in the @ModelAttribute section for WebFlux. Thus it appears to be a general issue related to examples within a given section of the documentation when some examples have callouts and others do not, likely due to a bug in the Javascript that provides this feature. See gh-29505 --- framework-docs/src/docs/asciidoc/web/webmvc.adoc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/framework-docs/src/docs/asciidoc/web/webmvc.adoc b/framework-docs/src/docs/asciidoc/web/webmvc.adoc index 16c48ca3e8ac..bd75b8438c6f 100644 --- a/framework-docs/src/docs/asciidoc/web/webmvc.adoc +++ b/framework-docs/src/docs/asciidoc/web/webmvc.adoc @@ -2662,19 +2662,21 @@ query parameters and form fields. The following example shows how to do so: .Java ---- @PostMapping("/owners/{ownerId}/pets/{petId}/edit") - public String processSubmit(@ModelAttribute Pet pet) { + public String processSubmit(@ModelAttribute Pet pet) { // <1> // method logic... } ---- +<1> Bind an instance of `Pet`. [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] .Kotlin ---- @PostMapping("/owners/{ownerId}/pets/{petId}/edit") -fun processSubmit(@ModelAttribute pet: Pet): String { +fun processSubmit(@ModelAttribute pet: Pet): String { // <1> // method logic... } ---- +<1> Bind an instance of `Pet`. The `Pet` instance above is sourced in one of the following ways: @@ -2702,18 +2704,21 @@ could load the `Account` from a data store: .Java ---- @PutMapping("/accounts/{account}") - public String save(@ModelAttribute("account") Account account) { + public String save(@ModelAttribute("account") Account account) { // <1> // ... } ---- +<1> Bind an instance of `Pet` using an explicit attribute name. + [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] .Kotlin ---- @PutMapping("/accounts/{account}") - fun save(@ModelAttribute("account") account: Account): String { + fun save(@ModelAttribute("account") account: Account): String { // <1> // ... } ---- +<1> Bind an instance of `Pet` using an explicit attribute name. After the model attribute instance is obtained, data binding is applied. The `WebDataBinder` class matches Servlet request parameter names (query parameters and form