Announcement Announcement Module
Collapse
No announcement yet.
Neo4J roo MVC scaffolding. update problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Neo4J roo MVC scaffolding. update problem

    Hi,

    aj code generated for updating it's not working properly.

    Code:
    @RequestMapping(method = RequestMethod.PUT)
        public String AccountController.update(@Valid Account account, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
            if (bindingResult.hasErrors()) {
                uiModel.addAttribute("account", account);
                return "accounts/update";
            }
            uiModel.asMap().clear();
            account.save();
            return "redirect:/accounts/" + encodeUrlPathSegment(account.getId().toString(), httpServletRequest);
        }
    In the example showed above, the account entity does not have the id field informed so Neo4j treat it as a new instance, creating a new one and not updating the edited one.

    Could you please give me a hand?

    Thanks
    Last edited by jcataluna; Nov 2nd, 2011, 03:56 PM. Reason: tags

  • #2
    Hey,

    Yes, that is a problem with the current addon. You should copy that generated code up into your controller to override it. A simple workaround would be to implement this:

    Code:
        @RequestMapping(method = RequestMethod.PUT)
        public String update(@Valid Account account, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest,
        		@RequestParam(value = "id", required = true) Long nodeId) {
            if (bindingResult.hasErrors()) {
                uiModel.addAttribute("todo", todo);
                return "todos/update";
            }
            // this is the critical bit...
            Node node = gdc.getNodeById(nodeId);
            account.setPersistentState(node);
    
            uiModel.asMap().clear();
            todo.save();
            return "redirect:/todos/" + encodeUrlPathSegment(todo.getId().toString(), httpServletRequest);
        }
    You'll also need to add the 'gdc' field to your controller:

    Code:
        @Autowired GraphDatabaseContext gdc;
    Note that this approach only works with the stable released version of Spring Data Neo4j 1.1.0.RELEASE. Things are changing with the pending release of 2.0 and the Roo addon is being updated to work with the new release.

    Cheers,
    Andreas

    Comment


    • #3
      Thanks for the reply!

      im still trying to get it to work. I will get back to you.

      Cheers.

      Comment

      Working...
      X