You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by Apache Wiki <wi...@apache.org> on 2006/06/26 19:01:16 UTC

[Myfaces Wiki] Update of "Setup For File Uploads" by DaveBrondsema

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Myfaces Wiki" for change notification.

The following page has been changed by DaveBrondsema:
http://wiki.apache.org/myfaces/Setup_For_File_Uploads

------------------------------------------------------------------------------
  }
  }}}
  
+ == Saving upload despite any validation errors ==
+ 
+ In many cases you will want to save the uploaded file, even if there are validation errors.  Otherwise the user must upload the file again, which is annoying and may be very time-consuming.  To do that, don't value-bind the component to a backing bean, but use a ValueChangeListener and set immediate="true".
+ {{{
+ <t:inputFileUpload storage="file" immediate="true">
+ 	<f:valueChangeListener type="com.myorg.foo.UploadListener" />
+ </t:inputFileUpload>
+ }}}
+ 
+ {{{
+ public class UploadListener implements ValueChangeListener {
+ 	public void processValueChange(ValueChangeEvent event) throws AbortProcessingException {
+ 		UploadedFile uploadedFile = (UploadedFile) event.getNewValue();
+ 		
+ 		// do something with uploadedFile
+ 	}
+ }
+ }}}
+ 
+ It's up to you to decide what to do with uploadedFile in your UploadListener.  One possibility might be to store the file in a temporary folder, using the session id (from ExternalContext).  When the form is finally submitted, persist your data to the database and then move the file to a new final directory using the database ID.
+