Results 1 to 3 of 3

Thread: Adding enctype="multipart/form-data" to form tag causes problem with update

  1. #1
    Join Date
    Apr 2011
    Posts
    28

    Default Adding enctype="multipart/form-data" to form tag causes problem with update

    Hi,

    I'm adding support for file upload. I've added enctype="multipart/form-data" to a form tag and it's breaking update CRUD operation.


    I've changed update.tagx from

    Code:
    <form:form action="${fn:escapeXml(form_url)}" method="PUT" modelAttribute="${modelAttribute}">
    to
    Code:
    <form:form action="${fn:escapeXml(form_url)}" method="PUT" modelAttribute="${modelAttribute}" enctype="multipart/form-data" >
    Now, When I'm trying to edit entitity with Roo generated form, it's causing hibernate unhandled exception, unable to persist detached object.

    After debugging, I've discovered that instead of update method
    Code:
        @RequestMapping(method = RequestMethod.PUT)
        public String TipLokacijeController.update(@Valid TipLokacije tipLokacije, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
            if (bindingResult.hasErrors()) {
                uiModel.addAttribute("tipLokacije", tipLokacije);
                return "tiplokacijes/update";
            }
            uiModel.asMap().clear();
            tipLokacije.merge();
            return "redirect:/tiplokacijes/" + encodeUrlPathSegment(tipLokacije.getId().toString(), httpServletRequest);
        }
    create method is being called,
    Code:
        @RequestMapping(method = RequestMethod.POST)
        public String TipLokacijeController.create(@Valid TipLokacije tipLokacije, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
            if (bindingResult.hasErrors()) {
                uiModel.addAttribute("tipLokacije", tipLokacije);
                return "tiplokacijes/create";
            }
            uiModel.asMap().clear();
            tipLokacije.persist();
            return "redirect:/tiplokacijes/" + encodeUrlPathSegment(tipLokacije.getId().toString(), httpServletRequest);
        }
    How can I add support for file upload without breaking "update" CRUD operation

    Thank you for your answers

  2. #2
    Join Date
    Jun 2010
    Posts
    440

    Default

    This reference might help you http://viralpatel.net/blogs/2011/02/...-tutorial.html.


    B Roogards
    jD

  3. #3
    Join Date
    Apr 2011
    Posts
    28

    Default

    thank you for the answer

    Code:
     I am not allowing updates in this version of the application. So, I disabled it, by setting the update=false in the @RooWebScaffold annotation.
    I will do the same, although it's a workaround, for now, until I figure it out, it will do fine

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •