Jacel
Jacel

Reputation: 347

Spring controller not triggered

I have this table in a template. There are two buttons in the table cell

<td>
<form action="#" data-th-action="@{/userdash}" method="POST">
    <input type="hidden" name="id" th:value="${acc.recordId}" />                                                 
    <button type="submit" name="action" value="reengage">Re Engage</button>
    <button type="submit" name="action" value="reinvoice">invoice</button>
</form>     

When Re Engage is clicked, I expect the following to be triggered.:

/*User dashboard:customer clicks invoice*/
@PostMapping(value="/userdash", params="action=reinvoice")
public ModelAndView reinvoice(@RequestParam String id,Authentication authentication) {

when invoice is clicked, I expect:

/*User dashboard:customer clicks re-engage*/
@PostMapping(value="/userdash", params="action=reengage")
public ModelAndView reengage(@RequestParam String recordId, Authentication authentication) {

But only the reinvoice method is executed when clicking the invoice button. The reengage method fails to execute when clicking the re engage button

What did I do wrong?

Upvotes: 1

Views: 48

Answers (1)

smali
smali

Reputation: 4805

//*User dashboard:customer clicks re-engage*/
@PostMapping(value="/userdash", params="action=reengage")
public ModelAndView reengage(@RequestParam String recordId, Authentication 
authentication) {

Change rocordId to id and try. like below:

/*User dashboard:customer clicks re-engage*/
@PostMapping(value="/userdash", params="action=reengage")
public ModelAndView reengage(@RequestParam String id, Authentication 
authentication) {

The problem in above code is requestParam is expecting recordId and you are passing param as id

Upvotes: 1

Related Questions