Using - Spring Boot, Thymeleaf
I have following code under controller class:
public class HotelController {
private HotelService hotelService;
private HotelRepository hotelRepository;
@Autowired
public HotelController(HotelService hotelService,HotelRepository hotelRepository) {
this.hotelService = hotelService;
this.hotelRepository = hotelRepository;
}
@GetMapping("/index")
public String searchHotel(Model model) {
Hotel hotel = new Hotel();
model.addAttribute("searchObject",hotel);
model.addAttribute("cityList", hotelRepository.findListOfCities());
model.addAttribute("hotelList", hotelRepository.findListOfHotels());
return "search_hotel";
}
@PostMapping("/availabilityResult")
public String afterClickingSearch(@ModelAttribute("searchObject") Hotel hotel,Model model) {
if(hotelService.searchHotelResult(hotel)==null)
return "failure_page";
else {
model.addAttribute("hotelRoom_TypePriceGST",hotelService.findHotelPriceandRoomType(hotel.getCity(),hotel.getHotel()).split(","));
model.addAttribute("total", hotelService.findTotal(hotel.getCity(), hotel.getHotel()));
return "booking_confirmation";
}
}
@GetMapping("/navUserRegisterPage")
public String userRegisterPage(Model model){
User user = new User();
model.addAttribute("userObj", user);
return "user_registerForm";
}
@PostMapping("/reserveUser")
public String reserveUserHandler(@ModelAttribute("userObj") User user,@ModelAttribute("searchObject") Hotel hotel,Model model) {
System.out.println(hotel.getHotel());
System.out.println(user.getGuest_name());
model.addAttribute("hotelName", hotel.getHotel());
model.addAttribute("userName", user.getGuest_name());
return "confirmation_page";
}
}
I can find hotel value(usig hotel.getHotel()) under handler method- public String afterClickingSearch()
But when I try to find the hotel value(using hotel.getHotel()) under handler method -reserveUserHandler(); I get null as value.
Please help with how can I retrieve hotel value under reserveUserHandler() method.