public void displayAccomUpdate(Accommodation acc) { // curAccomUpdate = null; curAccomUpdate = new Accommodation(); curAccomUpdate.setAccomName(acc.getAccomName()); curAccomUpdate.setDescription(acc.getDescription()); curAccomUpdate.setAddress(acc.getAddress()); curAccomUpdate.setNoOfBed(acc.getNoOfBed()); curAccomUpdate.setNoOfPersons(acc.getNoOfPersons()); curAccomUpdate.setNoOfToilet(acc.getNoOfToilet()); curAccomUpdate.setPrice(acc.getPrice()); Gson gson = new Gson(); String jsonRoom = gson.toJson(curAccomUpdate); UpdateRoomResult = jsonRoom; }
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"; }