abc
abc

Reputation: 512

Error: Could not parse as expression, th:action

I want to do an POST request with Thymeleaf and Spring. My goal is to receive the selected information from HTML. But initial I want only to redirect me when I push the submit button for the following link from th:action - "cidashboard/table".

My controller :

   @GetMapping("cidashboard/filter/data")
    public String allDataForFilter(Model model) {
        model.addAttribute("projectsVariants", projectVariantService.findAllProjectsVariants());
        model.addAttribute("builds", buildService.findAllBuildFromDB());
        model.addAttribute("misraMessages", misraMessagesService.findAllMisraMessagesFromDb());

        return "test2";
    }

    @PostMapping("cidashboard/table")
    public String createTable() {
        return "test1";
    }

My html page:

<form th:action="@/cidashboard/table" method="post">
    <select class="form-control">
        <option  th:each = "projectVariant : ${projectsVariants}" th:selected="${projectVariant.getProjectVariantId()}"  th:text="${projectVariant.getProjectVariantName()}"></option>
    </select>
    <input type="submit" value="submit"/>
</form>

I received this error:

Could not parse as expression: "@/cidashboard/table" 

Upvotes: 1

Views: 1665

Answers (1)

Mihai Alexandru-Ionut
Mihai Alexandru-Ionut

Reputation: 48437

Due to documentation, you have to wrap the relative path within brackets.

<form th:action="@{/cidashboard/table}" method="post">

which is parsed to

<form action="/cidashboard/table" method="post">

Upvotes: 2

Related Questions