Anybody has an idea what's going on? Why I can't delete my Car?
I have the following error in the web page: There was an unexpected error (type=Bad Request, status=400). Parameter conditions "idCar" not met for actual request parameters:
These code is work if I will write the following address into web browser bar: http://localhost:8080/cars-web/deleteCar?idCar=2"
This is Code from CarGui with adnotation @Controller
@GetMapping(value = "/cars-web/deleteCar", params = "idCar")
public String deleteCar(@RequestParam long idCar) {
carService.deleteCar(idCar);
return "redirect:/cars-web";
}
This is the code from my CarService
@Override
public boolean deleteCar(long id) {
Optional<Car> found = carList.stream().filter(car -> car.getCarId()== id).findFirst();
if(found.isPresent()) {
carList.remove(found.get());
return true;
} else {
return false;
}
}
And here is my code from my web page:
<form th:action="@{/cars-web/deleteCar}" th:object="${someId}" method="get">
<p>Id:<select>
<option th:each="ids : ${readId2}"
th:value="${ids}" th:text="${ids}"></option>
</select></p>
<p><input type="submit" value="Delete Car From List"></p>
Additionally my model
@GetMapping("/cars-web")
public String getCars(Model model) {
model.addAttribute("carList", carService.getAllCars());
model.addAttribute("readId", carService.getListId());
model.addAttribute("readId2", carService.getListId());
model.addAttribute("addCar", new Car());
model.addAttribute("color", carService.getAllCarColors());
model.addAttribute("someId", "");
return "cars-web";
}