Q:

How to submit the information from a drop-down list to the Spring Controller?

I want to pass the information about what project I selected from a list of projects. For that I made an HTML page that contains a form. 
<form th:action="@{/cidashboard/table}" th:object="${projectVariantSelected}" method="post">

<p>Project variants options:</p>
    <select class="form-control" th:field="*{projectVariantId}">
        <option  th:each = "projectVariant : ${projectsVariants}"
                 th:value="${projectVariant.projectVariantId}"
                 th:text="${projectVariant.projectVariantName}">
        </option>
    </select>

<input type="submit" value="submit"/>
</form>

This is my POST request: 
@PostMapping("cidashboard/table")
 public String createTable(@ModelAttribute("projectVariantSelected") ProjectVariant projectVariantSelected) {

 System.out.println("Project Variant selected: " + projectVariantSelected.getProjectVariantName() + projectVariantSelected.getProjectVariantId());

 return "test1";
}

I received this error: 
Neither BindingResult nor plain target object for bean name 'projectVariantSelected' available as request attribute

A:

The id from th:object must represent an existing object from the model. You can do something like this in your controller:
@ModelAttribute
public void addAttributes(Map<String,Object> model) {
    model.put("projectVariantSelected", new ProjectVariant());
}

Your model attribute must be initialized before returning the view. Spring tags will take your thymeleaf view fields and will populate the available model attribute.

