public void roomRating() { // FacesContext context = FacesContext.getCurrentInstance(); // context.addMessage(null, new FacesMessage("Successful", "Your message: ")); // context.addMessage(null, new FacesMessage("Second Message", "Additional Message // Detail")); try { Rating rate = new Rating(); rate.setRateId(1); rate.setCustId(curAccom.getCustId()); rate.setAccomId(curAccom); rate.setScore(Integer.parseInt(roomRatingSelected)); ratingFacade.create(rate); } catch (Exception ex) { printStackTrace(); } }
public String displayRoomDetail(int id) { try { Accommodation accom = accommodationFacade.find(id); if (accom != null) { curAccom = new Accommodation(); curAccom.setAccomName(accom.getAccomName()); curAccom.setDescription(accom.getDescription()); curAccom.setPrice(accom.getPrice()); curAccom.setAccomId(id); curAccom.setNoOfBed(accom.getNoOfBed()); curAccom.setNoOfPersons(accom.getNoOfPersons()); curAccom.setNoOfToilet(accom.getNoOfToilet()); curAccom.setCustId(customerFacade.find(1)); List<Comments> commentsCount = commentsFacade.findCommentsByAccomId( id); // != null ? commentsFacade.findCommentsByAccomId(id).size() : 0; Gson gson = new Gson(); RoomImage roomImage = gson.fromJson(accom.getImages(), RoomImage.class); // curAccom.setImages(accom.getImages()); slider1 = roomImage.getSlider1(); slider2 = roomImage.getSlider2(); slider3 = roomImage.getSlider3(); List<Rating> ratings = ratingFacade.findByAccRoomId(id); int sumRateScore = 0; for (Rating rate : ratings) { sumRateScore += rate.getScore(); } displayRate = ratings.size() > 0 ? sumRateScore / ratings.size() : 0; } } catch (Exception ex) { printStackTrace(); } return "roomdetail"; }