1
I need to get an id value of a dynamic span and I’m not getting it. What I’m doing wrong?
Error:
There was an Unexpected error (type=Bad Request, status=400).
Required Long Parameter 'id' is not present
View:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"></meta>
<title>CRUD</title>
<link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<h1>Edit or Delete User</h1>
<table class="table table-hover">
<thead>
<tr>
<th>Id</th>
<th>User</th>
</tr>
</thead>
<td><span th:text=${user.id} name="id"></span></td>
<td><span th:text=${user.name} name="name"></span></td>
</table>
<form action="../update" method="post">
<div id="userEdit"></div>
<div>
<td><label for="userpassword">Password:</label> <input
type="text" id="userpassword" name="user_password"></td>
</div>
<div class="button">
<button type="submit">Update</button>
</div>
</form>
<hr>
<form action="deleteUser" method="post">
<div class="button">
<button type="submit">Delete</button>
</form>
</body>
</html>
Method:
@RequestMapping(value = "update", method = RequestMethod.POST)
public ModelAndView updateUser(@RequestParam("id") Long id,
@RequestParam("user_password") String newPassword) {
User user = dao.find(id);
User newUser = dao.find(user.getId());
newUser.setPassword(newPassword);
dao.save(newUser);
return new ModelAndView("redirect:crud");
}
I’m wearing spring and Thymeleaf.