Results 1 to 3 of 3

Thread: Binding to File Input Type

  1. #1

    Default Binding to File Input Type

    Well, I think I'm pretty close to having my image upload form complete, however, I'm trying to figure out how I can maintain the uploaded image if validation errors occur upon form submit.

    Basically, I do not want the end-users thinking that they must re-upload their image each time form validation fails. It would be nice if the uploading process does not occur if form validation errors occur, and even nicer if the image upload field maintained the path selected by the user.

    Anyhow, here's the code I have so far:

    In my Controller:

    Code:
    	protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    		binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
    		super.initBinder(request, binder);
    	}
    In my JSP:


    Code:
            <spring&#58;bind path="command.imageOne">
              <input type="file" name="<c&#58;out value="$&#123;status.expression&#125;"/>" value="<c&#58;out value="$&#123;status.value&#125;"/>">
            </spring&#58;bind>
    Also, in my command model, imageOne is defined as a byte[].

    Any help is greatly appreciated!

    Thanks,

    Matt

  2. #2
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    A couple of points:

    - the HTML spec prevents the setting of the file upload control for security purposes (imagine adding a hidden one preset with some critical file )
    - the only way to *not* do fileupload on validation is to do them on two seperate pages.
    - if you want to keep the user's file data between requests, you can store your formBackingObject on the session. You can then on the jsp check if the formBackingObject.yourFile is empty or not.

    Also, what is the purpose of the "value" element on the file input type?

  3. #3

    Default Binding to File Input Type

    Yatesco,

    Thank you very much for your reply, I more than appreciate it.

    Putting the value element in the HTML tag was my futile attempt in retrieving the full path name to the image, however, per your point below, this is obviously not an option, due to the HMTL spec.

    Again, thanks for your reply.

    Matt

Similar Threads

  1. Unit testing with JOTM and JtaTransactionManager
    By lalle in forum Architecture
    Replies: 1
    Last Post: Oct 15th, 2005, 09:05 AM
  2. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  3. Replies: 4
    Last Post: Aug 17th, 2005, 04:42 AM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM

Posting Permissions

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