Thymeleaf: pass input text as parameter in form action

Viewed 21983

I'm quite new to Thymeleaf, so I'm struggling with this.

I want to pass a parameter to the controller when submitting a form, with the value of a text field.

This is my controller:

@PostMapping("/postEndpoint/{myid}")
public String pidUserSubmit(@PathVariable(value = "myid") String myid) {
    log.debug("*** MY ID: {}", myid);
    return "redirect:/someOtherPage";
}

This is how I've defined the text input:

<input id="myid" name="myid" type="text" maxlength="26" title="Please enter a valid ID" class="texter" th:value="*{myid}">

And this is what I've tried in my html file with thymeleaf:

<form name="myform" id="myform" action="#" th:action="@{/postEndpoint/__${myid}__}" method="post">

I'm getting this log: *** MY ID: null

<form name="myform" id="myform" action="#" th:action="@{/postEndpoint/${myid}}" method="post">

I'm getting this log: *** MY ID: ${myid}

<form name="myform" id="myform" action="#" th:action="@{/postEndpoint/{myid}(myid=${myid})}" method="post">

This is not even getting to the controller

Any help would be appreciated! :)

2 Answers
Related