I want to create a website that displays a form.
The fields of the form depend on a request parameter (and also the form backing bean).
This is my controller that renders the different forms:

```
@Controller
public class TestController {

    @Autowired
    private MyBeanRegistry registry;

    @RequestMapping("/add/{name}")
    public String showForm(@PathVariable String name, Model model) {
        model.addAttribute("name", name);
        model.addAttribute("bean", registry.lookup(name));

        return "add";
    }

}

```

The corresponding view looks like this:

```
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
</head>
<body>
    <form method="post" th:action="@{|/add/${name}|}" th:object="${bean}">
        <th:block th:replace="|${name}::fields|"></th:block>
        <button type="submit">Submit</button>
    </form>
</body>
</html>

```

Following is an example fragment that displays the form fields:

```
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
</head>
<body>
    <th:block th:fragment="fields">
        <label for="firstName">First name</label><br />
        <input type="text" id="firstName" th:field="*{firstName}" /><br />
        <label for="lastName">Last name</label><br />
        <input type="text" id="lastName" th:field="*{lastName}" />
    </th:block>
</body>
</html>

```

The looked up bean would be like this:

```
public class MyExampleBean {

    private String firstName;

    private String lastName;

    // Getters & setters

}

```

The form is rendered correctly, but how can I receive the form back in the controller?
And how can I validate the submitted bean? I tried the following method, but obviously
it can not work:

```
@RequestMapping(value = "/add/{name}", method = RequestMethod.POST)
public String processForm(@PathVariable String name, @Valid Object bean) {
    System.out.println(bean);

    return "redirect:/add/" + name;
}

```

Spring creates a new instance of `Object` but the submitted values are lost.
So how can I accomplish this task?