@RequestMapping(value = "/{id}", params = "removeNode", method = RequestMethod.GET) public String removeNode(@PathVariable("id") Long id, Model uiModel) { Node nodeToRemove = nodeService.findById(id); nodeService.remove(nodeToRemove); uiModel.addAttribute("newNode", new Node()); return "nodes/list"; }
@RequestMapping(params = "addNode", method = RequestMethod.POST) public String addNode( @ModelAttribute("newNode") @Valid Node newNode, BindingResult bindingResult, Model uiModel, RedirectAttributes redirectAttributes, Locale locale) { validateNode(newNode.getName(), newNode.getAddress(), bindingResult); if (bindingResult.hasErrors()) { uiModel.addAttribute( "message", new Message( "error", messageSource.getMessage("label_node_add_failure", new Object[] {}, locale))); uiModel.addAttribute("newNode", newNode); return "nodes/list"; } // uiModel.asMap().clear(); // redirectAttributes.addFlashAttribute("message") uiModel.addAttribute( "message", new Message( "success", messageSource.getMessage("label_node_add_success", new Object[] {}, locale))); nodeService.save(newNode); uiModel.addAttribute("newNode", new Node()); return "nodes/list"; }
private void validateNode(String nodeName, String nodeAddress, Errors errors) { Node node; if ((node = nodeService.findByNameAndAddress(nodeName, nodeAddress)) != null) { errors.rejectValue( "name", "label_node_duplicate_name_address", new String[] {nodeName, nodeAddress}, null); } }
@RequestMapping(value = "/listgrid", method = RequestMethod.GET, produces = "application/json") @ResponseBody public NodeGrid listGrid( @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "rows", required = false) Integer rows, @RequestParam(value = "sidx", required = false) String sortBy, @RequestParam(value = "sord", required = false) String order) { Sort sort = null; String orderBy = sortBy; if (orderBy != null && orderBy.equals("name")) { orderBy = "name"; } if (orderBy != null && order != null) { if (order.equals("desc")) { sort = new Sort(Sort.Direction.DESC, orderBy); } else sort = new Sort(Sort.Direction.ASC, orderBy); } PageRequest pageRequest = null; if (sort != null) { pageRequest = new PageRequest(page - 1, rows, sort); } else { pageRequest = new PageRequest(page - 1, rows); } Page<Node> nodePage = nodeService.findByPage(pageRequest); NodeGrid nodeGrid = new NodeGrid(); nodeGrid.setCurrentPage(nodePage.getNumber() + 1); nodeGrid.setTotalPages(nodePage.getTotalPages()); nodeGrid.setTotalRecords(nodePage.getTotalElements()); List<Node> nodes = Lists.newArrayList(nodePage.iterator()); nodeGrid.setNodeData(checkAccessiblity(nodes)); return nodeGrid; }