@RequestMapping( value = "deleteProperty/delete/{ID}", method = {RequestMethod.GET}, headers = "Accept=*/*", produces = "application/json") // Ajax controller public @ResponseBody ModelAndView execute2( @PathVariable(value = "ID") Long ID, HttpServletRequest request) { HttpSession session = request.getSession(); String userName = (String) session.getAttribute("userName"); String userPassword = (String) session.getAttribute("userPassword"); User user = new User(); List<Property> clientProperties = new ArrayList<>(); Property propertyToDelete = new Property(); String message = ""; try { propertyToDelete = propertyDao.findPropertyById(ID); List<PropertyOwner> owners = propertyToDelete.getPropertyOwners(); List<Utility> utilities = propertyToDelete.getPropertyUtilities(); List<Photo> photos = propertyToDelete.getPropertyPhotos(); owners.clear(); utilities.clear(); photos.clear(); propertyDao.delete(ID); message = "Property Nr." + ID + " deleted successfully!"; user = userDao.findUserByCredentials(userName, userPassword); if (user != null) { clientProperties = propertyDao.findPropertyByClient(user); user.setListOfProperties(clientProperties); } } catch (DBException e) { System.out.println("Error!"); } List<Property> propertiesOfThisUser = user.getListOfProperties(); ModelAndView modelAndView = new ModelAndView(); modelAndView.addObject("model", propertiesOfThisUser); modelAndView.addObject("message", message); modelAndView.setViewName("/deleteSpecificProperty"); return modelAndView; }
@RequestMapping( value = "deleteProperty", method = {RequestMethod.GET}) // Ajax controller public ModelAndView execute(HttpServletRequest request) { HttpSession session = request.getSession(); String userName = (String) session.getAttribute("userName"); String userPassword = (String) session.getAttribute("userPassword"); User user = new User(); List<Property> clientProperties = new ArrayList<>(); try { user = userDao.findUserByCredentials(userName, userPassword); if (user != null) { clientProperties = propertyDao.findPropertyByClient(user); user.setListOfProperties(clientProperties); } } catch (DBException e) { System.out.println("Error!"); } List<Property> propertiesOfThisUser = user.getListOfProperties(); return new ModelAndView("deleteSpecificProperty", "model", propertiesOfThisUser); }