Results 1 to 3 of 3

Thread: Form POST breaks following 3.0 to 3.1 upgrade

  1. #1
    Join Date
    Jan 2009
    Posts
    22

    Default Form POST breaks following 3.0 to 3.1 upgrade

    Hi all,

    I've upgraded from 3.0.5 to 3.1.3.RELEASE. Quite a few things broke as I didn't realise the enormity of the demise of AnnotationMethodHandlerAdapter. However, I got this all back up and running with a custom Java code-based WebConfig and fixes to some of my RequestMappings. All good.

    However, now when I come to POST a form which previously worked fine, I'm seeing unexpected behaviour. I use SessionAttributes to keep track of my form-backing objects, and have a controller like so:

    Code:
    @Controller
    @RequestMapping("/foo")
    @SessionAttributes("foo")
    public class EditFooController {
    
    ...
    
      @RequestMapping(value = {"", "/{fooId}"}, method = RequestMethod.POST)
      public String processSubmit(@ModelAttribute("foo") Foo<? extends Fooable> foo,
                                  ModelMap model,
                                  SessionStatus session) throws IOException {
        requestManager.save(foo);
        session.setComplete();
        model.clear();
        return "redirect:/foo/" + foo.getId();
      }
    }
    Foo objects contain a member Collection<Bar> variable that can have elements added and removed via the form. Adding Bar elements always works fine. Removing Bar elements does not work. I can see in my custom WebBindingInitializer that Spring is correctly passing only the remaining form elements, and not the removed ones. Removing elements in 3.0.x used to work fine with this exact configuration. In 3.1, it does not.

    I tried removing the SessionAttribute annotation so that I know I'm getting a new Foo on POST, but get a "Specified class is an interface" error. I don't really want to have to specify a concrete Foo implementation via a @ModelAttribute annotated method (plus, this worked before, as I said).

    Any thoughts?

    Cheers

    Rob

  2. #2
    Join Date
    Jan 2009
    Posts
    22

    Default

    As an update, case 2 in the first answer here outlines my issue: http://stackoverflow.com/questions/1...em-from-a-list

    Seemingly, Spring 3.0.5 used to completely replace the given collection of elements, whereas 3.1.x seems to just edit the collection in place, leaving unwanted elements still in the original model collection.

  3. #3
    Join Date
    Jan 2009
    Posts
    22

    Default

    OK so now I feel stupid. I refactored some code in my backing object setter for the collection in question, and didn't put any kind of clear() in there. *sigh* Apologies for the forum noise.

Posting Permissions

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