Using File Upload components

Use the File Upload component to create a way for users to upload a file to the server. This component consists of an input field and an associated Browse button.
The user can manually specify the file in the input field or can browse for a file by clicking Browse. To use a file upload component on a Faces JSP file:
  1. Drag a File Upload component from the Faces Components drawer on the palette to the Faces JSP file.
  2. In the Properties view for the File Upload component (fileupload), enter the value (in the Value field) to which you want to bind the file upload component. You can also click the browse button to search for a value. The value can be a byte[], a String (file content will be Base64 encoded) or a java.io.OutputString object. The file upload component is usually bound to data storage, such as a database or a JavaBean. When the page with the file upload component is submitted, the content of the file is stored in the specified location (a column in the database or a property of the bean).
  3. In the Validation panel of the Properties view:
    1. Check Value is required if you want to require that the user specify a file.
    2. Specify in MIME notation the types of files that the user can upload. Use MIME notation and separate file extensions with commas (for example: text/html, image/gif).
    3. Specify the file types you do not want the user to upload. Separate file extensions with commas (for example: xml, bat, exe).
    4. You can supply additional validation in the Value Changed event in the Quick Edit view. Click the button next to Click to create/edit custom validation code to switch to the Quick Edit view.

To learn more about using the File Upload component, complete the following tutorial, especially the exercise on using the file upload component:

Tutorial: Display dynamic information on Web pages with JavaServer Faces. This tutorial will teach you how to design a dynamic Web site that functions as a newspaper's classified advertising section. The Web site is a complete J2EE Web application that uses JavaServer Faces (JSF) components and Service Data Objects (SDO) components. The Web application uses JSF technology to create dynamic Web pages that link to a database that stores classified advertising data.Tutorial: Display dynamic information on Web pages with JavaServer Faces. This tutorial will teach you how to design a dynamic Web site that functions as a newspaper's classified advertising section. The Web site is a complete J2EE Web application that uses JavaServer Faces (JSF) components and Service Data Objects (SDO) components. The Web application uses JSF technology to create dynamic Web pages that link to a database that stores classified advertising data.

Related tasks
Creating an input form connected to a data source
Adding input components to a Faces JSP page
Adding selection lists to a Faces JSP file
Adding hyperlinks to a Faces JSP file
Using navigation rules with Faces JSP pages
Managing errors in JavaServer Faces applications
Creating a Faces JSP file
Related reference
File Upload

Feedback