Class FileField

  • All Implemented Interfaces:
    Serializable, org.apache.click.Stateful, org.openidentityplatform.openam.click.Control

    public class FileField
    extends Field
    Provides a File Field control:   <input type='file'>.
    Example
    File Field <input type='file' value=''/>
    The FileField control uses the Jakarta Commons FileUpload library to provide file processing functionality.

    You can control the maximum request size and maximum file size by configuring CommonsFileUploadService.

    Note Browsers enforce the JavaScript value property as readonly to prevent script based stealing of users files.

    You can make the file field invisible by setting the CSS display attribute, for example:

     <form method="POST" enctype="multipart/form-data">
        <input type="file" name="myfile" style="display:none" onchange="fileName=this.value">
        <input type="button" value="open file" onclick="myfile.click()">
        <input type="button" value="show value" onclick="alert(fileName)">
     </form> 

    Please also see the references:

    See Also:
    Serialized Form
    • Field Detail

      • VALIDATE_FILEFIELD_FUNCTION

        protected static final String VALIDATE_FILEFIELD_FUNCTION
        The field validation JavaScript function template. The function template arguments are:
        • 0 - is the field id
        • 1 - is the Field required status
        • 2 - is the localized error message
        See Also:
        Constant Field Values
      • size

        protected int size
        The text field size attribute. The default size is 20.
      • fileItem

        protected org.apache.commons.fileupload.FileItem fileItem
        The DefaultFileItem after processing a file upload request.
    • Constructor Detail

      • FileField

        public FileField​(String name)
        Construct the FileField with the given name.
        Parameters:
        name - the name of the field
      • FileField

        public FileField​(String name,
                         boolean required)
        Construct the FileField with the given name and required status.
        Parameters:
        name - the name of the field
        required - the field required status
      • FileField

        public FileField​(String name,
                         String label)
        Construct the FileField with the given name and label.
        Parameters:
        name - the name of the field
        label - the label of the field
      • FileField

        public FileField​(String name,
                         String label,
                         boolean required)
        Construct the FileField with the given name, label and required status.
        Parameters:
        name - the name of the field
        label - the label of the field
        required - the required status
      • FileField

        public FileField​(String name,
                         String label,
                         int size)
        Construct the FileField with the given name, label and size.
        Parameters:
        name - the name of the field
        label - the label of the field
        size - the size of the field
      • FileField

        public FileField()
        Create an FileField with no name defined.

        Please note the control's name must be defined before it is valid.

    • Method Detail

      • getTag

        public String getTag()
        Return the FileField's html tag: input.
        Overrides:
        getTag in class AbstractControl
        Returns:
        this controls html tag
        See Also:
        AbstractControl.getTag()
      • getFileItem

        public org.apache.commons.fileupload.FileItem getFileItem()
        Return the FileItem after processing the request, or null otherwise.
        Returns:
        the FileItem after processing a request
      • getSize

        public int getSize()
        Return the field size.
        Returns:
        the field size
      • setSize

        public void setSize​(int size)
        Set the field size.
        Parameters:
        size - the field size
      • getType

        public String getType()
        Return the input type: 'file'.
        Returns:
        the input type: 'file'
      • getValidationJavaScript

        public String getValidationJavaScript()
        Return the FileField JavaScript client side validation function.
        Overrides:
        getValidationJavaScript in class Field
        Returns:
        the field JavaScript client side validation function
      • bindRequestValue

        public void bindRequestValue()
        Set the fileItem property from the multi-part form data submission.
        Overrides:
        bindRequestValue in class Field
      • onProcess

        public boolean onProcess()
        Overrides onProcess to use Context.getFileItem(String).
        Specified by:
        onProcess in interface org.openidentityplatform.openam.click.Control
        Overrides:
        onProcess in class Field
        Returns:
        true to continue Page event processing or false otherwise
        See Also:
        Field.onProcess()
      • render

        public void render​(HtmlStringBuffer buffer)
        Render the HTML representation of the FileField.
        Specified by:
        render in interface org.openidentityplatform.openam.click.Control
        Overrides:
        render in class AbstractControl
        Parameters:
        buffer - the specified buffer to render the control's output to
        See Also:
        AbstractControl.toString()
      • validate

        public void validate()
        Validate the FileField request submission.

        A field error message is displayed if a validation error occurs. These messages are defined in the resource bundle:

        • /click-control.properties
          • file-required-error
        Overrides:
        validate in class Field