Results 1 to 2 of 2

Thread: Annotated form and setBindEmptyMultipartFiles

  1. #1

    Unhappy Annotated form and setBindEmptyMultipartFiles

    Hi all,

    I'm hoping a member can help me.

    I am using the Spring Framework (in particular their Web MVC annotations) for an application I am working on but I've hit a bit of a snag.

    I have an annotated controller which uses a form backing object that contains (amongst other things) a MultipartFile.

    When I submit the form if I choose a file and then submit the code works fine. However if I don't choose a file and submit the form I get the following error:

    Code:
    Cannot convert value of type [java.lang.String] to required type [org.springframework.web.multipart.MultipartFile] for property 'imageFile'
    This is obviously a binding error. Does anyone know why it would be attempting the bind a string even if the item is empty?

    One thing I have tried is to edit the binder by doing the following:

    Code:
    @InitBinder("myObjectCommand")
    public void initBinder(WebDataBinder binder)
    {
        binder.setBindEmptyMultipartFiles(false);
    }
    But it seems to still attempt to bind the file?

    I've done a search of the forums but cannot seem to find anyone with the same error?

    For reference the command object behind my form is like this:

    Code:
    public class CategoryCommand
    {
        private MultipartFile imageFile=null;
        /**
         * @return the imageFile
         */
        public MultipartFile getImageFile()
        {
     	return imageFile;
        }
    
        /**
         * @param imageFile the imageFile to set
         */
        public void setImageFile(MultipartFile imageFile)
        {
            this.imageFile = imageFile;
        }
    }
    Also as a side note I have tested the functionality with a non annotated controller (so url mappings and definition in the servlet.xml) and this seemed to work fine but I would much rather use annotations? And you guys probably know that when something isn't working it bugs you until you find out why

    Any help would be much appreciated?!?

  2. #2

    Thumbs up Spring wins the day - PICNIC

    Hi all,

    Just to let people know this was a client side issue and nothing to do with Spring.

    I have been using a jQuery Ajax form plugin that submits my form via Ajax it is this that is making the form element default to a string?!

    Problem in chair not in computer - PICNIC

Tags for this Thread

Posting Permissions

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