sakai
Tag inputFileUpload


Widget that allows the user to upload a file. The uploaded file is available through the value of the component, through the FileItem interface. See the Apache commons-fileupload 1.0 API for details at http://jakarta.apache.org/commons/fileupload/. The recommended use of this widget is to use the valueChangeListener attribute to call a method that will process the uploaded file. The uploaded file is NOT persisted to storage automatically; the application is responsible for that, not the widget. The widget needs a filter configured in web.xml. The Sakai RequestFilter is recommended; however, a custom filter is permissable. The widget is compatible with the MyFaces filter ("extensionsFilter") as an alternative. A custom filter must expose the uploaded file though the commons-fileupload 1.0 FileItem interface, in one of two ways. It must be made available either as a request attribute with the field name, and would be accessible as follows: FileItem item = (FileItem) request.getAttribute(fieldName); OR as a method on a request wrapper with the following signature: public org.apache.commons.fileupload.FileItem getFileItem(String fieldName)

Example:
    
    In myfile.jsf:
    <f:view>
      <h:form enctype="multipart/form-data">   
         <sakai:inputFileUpload valueChangeListener="#{examplebean.processFileUpload}" />
         <h:commandButton value="Upload" type="submit" />
      </h:form>
    </f:view>
    
    In web.xml:
    <filter>
        <filter-name>sakai.request</filter-name>
        <filter-class>org.sakaiproject.util.RequestFilter</filter-class>
         <init-param>
        	<param-name>upload.enabled</param-name>
        	<param-value>true</param-value>
        </init-param>
    </filter>
    
    In ExampleBean.java:
         public void processFileUpload(ValueChangeEvent event) throws AbortProcessingException
         {
             try
             {
                 FileItem item = (FileItem) event.getNewValue();
	             String fieldName = item.getFieldName();
	             String fileName = item.getName();
	             long fileSize = item.getSize();
	             System.out.println("processFileUpload(): item: " + item + " fieldname: " + fieldName + " filename: " + fileName + " length: " + fileSize);
	        
	             // Read the file as a stream (may be more memory-efficient)
	             InputStream fileAsStream = item.getInputStream();
 
	             // OR INSTEAD read the contents as a byte array (probably less memory-efficient)
	             byte[] fileContents = item.get();
	        
	             // now process the file.  Do application-specific processing
	             // such as parsing the file, storing it in the database,
	             // or whatever needs to happen with the uploaded file.
             }
             catch (Exception ex)
             {
                 // handle exception
             }
         }
    
    


Tag Information
Tag Classorg.sakaiproject.jsf.tag.InputFileUploadTag
TagExtraInfo ClassNone
Body ContentJSP
Display NameNone

Attributes
NameRequiredRequest-timeTypeDescription
valuefalsefalsejava.lang.String The current value of this component. If the "directory" attribute is not used, the value of the component is the uploaded FileItem. If the "directory" attribute is used, the value of the component is the server-side absolute path to the uploaded file.
directoryfalsefalsejava.lang.String If present, the directory to which to persist uploaded files. Use of this attribute is discouraged. If this attribute is used, a tool which contains the tag will not be cluster-safe since different application servers probably do not share the same filesystem. If a file already exists and another file of the same name is uploaded, the existing file will be overwritten.
valueChangeListenerfalsefalsejava.lang.String This is the recommended way to access the uploaded file. The valueChangeListener will be called when a file is uploaded.MethodBinding representing a value change listener method that will be notified when a new value has been set for this input component. The expression must evaluate to a public method that takes a ValueChangeEvent parameter, with a return type of void.
stylefalsefalsejava.lang.String CSS style(s) to be applied to the underlying input tag when it is rendered.
styleClassfalsefalsejava.lang.String Space-separated list of CSS style class(es) to be applied when the underlying input tag is rendered. This value must be passed through as the "class" attribute on generated markup.
idfalsefalsejava.lang.String The component identifier for this component. This value must be unique within the closest parent component that is a naming container.
bindingfalsefalsejava.lang.String
renderedfalsefalsejava.lang.String Flag indicating whether or not this component should be rendered (during Render Response Phase), or processed on any subsequent form submit.
immediatefalsefalsejava.lang.String Flag indicating that this component's value must be converted and validated immediately (that is, during Apply Request Values phase), rather than waiting until Process Validations phase.
requiredfalsefalsejava.lang.String Flag indicating that the user is required to provide a submitted value for this input component.
validatorfalsefalsejava.lang.String MethodBinding representing a validator method that will be called during Process Validations to perform correctness checks on the value of this component. The expression must evaluate to a public method that takes FacesContext, UIComponent, and Object parameters, with a return type of void.
acceptfalsefalsejava.lang.String Pass-through attribute. Will be output as-is on the underlying input element.
alignfalsefalsejava.lang.String Pass-through attribute. Will be output as-is on the underlying input element.
accesskeyfalsefalsejava.lang.String Pass-through attribute. Will be output as-is on the underlying input element.
maxlengthfalsefalsejava.lang.String Pass-through attribute. Will be output as-is on the underlying input element.
sizefalsefalsejava.lang.String Pass-through attribute. Will be output as-is on the underlying input element.
disabledfalsefalsejava.lang.String Pass-through attribute. Will be output as-is on the underlying input element.
readonlyfalsefalsejava.lang.String Pass-through attribute. Will be output as-is on the underlying input element.
tabindexfalsefalsejava.lang.String Pass-through attribute. Will be output as-is on the underlying input element.

Variables
No Variables Defined.


Output Generated by Tag Library Documentation Generator. Java, JSP, and JavaServer Pages are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries. Copyright 2002-4 Sun Microsystems, Inc. 4150 Network Circle Santa Clara, CA 95054, U.S.A. All Rights Reserved.