Trying to pass 2 parameters from my thymeleaf view to my controller

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Trying to pass 2 parameters from my thymeleaf view to my controller

IrishGus
Hi
I am trying to pass 2 parameters to my AdminController.

My Controller:

@RequestMapping(value = "/editProd", method = RequestMethod.GET)
    public String getEdit(@RequestParam("bid") Integer categoryId, @RequestParam("cid") Integer itemId, Model model) {
   
    Item item2 = itemService.get(itemId);

    model.addAttribute("categoryId",categoryId);
    model.addAttribute("itemAttribute",item2);

    return "admin/adminEditProd";
        }


@RequestMapping(value = "/editProd", method = RequestMethod.POST)
    public String postEdit(@RequestParam("id") Integer itemId,
    @ModelAttribute("itemAttribute") Item item) throws IOException {
               
                item.setItemId(itemId);
                itemService.edit(item);

                return "redirect:/admin/adminCategories1";
        }


My Thymeleaf View Page:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4"
xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout">


<head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta name="description" content="The Store Yard - Portlaoise, Co. Laois" />
        <meta name="author" content="The Store Yard" />
       
        <link href="../resources/css/bootstrap.min.css" th:href="@{/resources/css/bootstrap.min.css}" rel="stylesheet" />
        <link rel="stylesheet" type="text/css" media="all" href="../resources/css/style.css" th:href="@{/resources/css/style.css}" />
        <script type="text/javascript" src="../resources/css/jquery.js" th:href="@{/resources/css/jquery.js}"></script>        <link th:href="@{/resources/css/font-awesome.min.css}" rel="stylesheet" />
        <link th:href="@{/resources/css/plugins/dataTables.bootstrap.css}" rel="stylesheet" />
        <link th:href="@{/resources/css/sb-admin.css}" rel="stylesheet" />

               
        <title>The Store Yard - Portlaoise, Co. Laois</title>
       
</head>

<body>
<div id="header">

 
</div>
<br></br>
<br></br>
<div id="content">
 
       

        <br></br>
        <br></br>
        <div>

                <fieldset>
                        <legend>

List of Categories

</legend>

                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                                         
                                                                       

                       
IDName
<input type="text" th:value="${category.categoryId}"/><input type="text" th:value="${category.categoryName}"/>DeleteEdit


                </fieldset>

        </div>
        <br></br>
        <br></br>
       

Create New Category

</div>
</body>
</html>


The Problem:

This is the URI that is created from my th:href link: http://localhost:8089/TheStoreYardApp/admin/editCat/'+%20$%7Bcategory.categoryId%7D

This seems to be a syntax error. The equivalent link in JSP looks like this: http://localhost:8089/TheStoreYardApp/admin//editCat?bid=10&cid=35

My URI is all screwed up with %207B% etc. I am a newbie to Thymeleaf so hopefully someone can help me.

Thanks in advance.
Gus Hayes