net.sf.click.control
Class FileField

java.lang.Object
  extended bynet.sf.click.control.AbstractControl
      extended bynet.sf.click.control.Field
          extended bynet.sf.click.control.FileField
All Implemented Interfaces:
Control, Serializable

public class FileField
extends Field

Provides a File Field control:   <input type='file'>.

File Field
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:

Author:
Malcolm Edgar
See Also:
Serialized Form

Field Summary
protected  FileItem fileItem
          The DefaultFileItem after processing a file upload request.
protected  int size
          The text field size attribute.
protected static String VALIDATE_FILEFIELD_FUNCTION
          The field validation JavaScript function template.
 
Fields inherited from class net.sf.click.control.Field
disabled, error, focus, form, help, label, readonly, required, tabindex, title, validate, value
 
Fields inherited from class net.sf.click.control.AbstractControl
actionListener, attributes, listener, listenerMethod, messages, name, parent, styles
 
Fields inherited from interface net.sf.click.Control
CONTROL_MESSAGES
 
Constructor Summary
FileField()
          Create an FileField with no name defined.
FileField(String name)
          Construct the FileField with the given name.
FileField(String name, boolean required)
          Construct the FileField with the given name and required status.
FileField(String name, String label)
          Construct the FileField with the given name and label.
FileField(String name, String label, boolean required)
          Construct the FileField with the given name, label and required status.
FileField(String name, String label, int size)
          Construct the FileField with the given name, label and size.
 
Method Summary
 void bindRequestValue()
          Set the fileItem property from the multi-part form data submission.
 int getControlSizeEst()
          Return the estimated rendered control size in characters.
 FileItem getFileItem()
          Return the FileItem after processing the request, or null otherwise.
 int getSize()
          Return the field size.
 String getTag()
          Return the FileFields's html tag: input.
 String getType()
          Return the input type: 'file'.
 String getValidationJavaScript()
          Return the FileField JavaScript client side validation function.
 void render(HtmlStringBuffer buffer)
          Render the HTML representation of the FileField.
 void setSize(int size)
          Set the field size.
 void validate()
          Validate the FileField request submission.
 
Methods inherited from class net.sf.click.control.Field
getError, getErrorLabel, getFocus, getFocusJavaScript, getForm, getHelp, getId, getLabel, getRequestValue, getTabIndex, getTextAlign, getTitle, getValidate, getValue, getValueObject, getWidth, isDisabled, isHidden, isReadonly, isRequired, isValid, onInit, onProcess, setDisabled, setError, setErrorMessage, setErrorMessage, setErrorMessage, setErrorMessage, setFocus, setForm, setHelp, setLabel, setListener, setParent, setReadonly, setRequired, setTabIndex, setTextAlign, setTitle, setValidate, setValue, setValueObject, setWidth
 
Methods inherited from class net.sf.click.control.AbstractControl
addStyleClass, appendAttributes, getActionListener, getAttribute, getAttributes, getContext, getHtmlImports, getMessage, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasStyles, onDeploy, onDestroy, onRender, registerActionEvent, removeStyleClass, renderTagBegin, renderTagEnd, setActionListener, setAttribute, setId, setName, setStyle, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VALIDATE_FILEFIELD_FUNCTION

protected static final String VALIDATE_FILEFIELD_FUNCTION
The field validation JavaScript function template. The function template arguments are:

See Also:
Constant Field Values

size

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


fileItem

protected 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 FileFields's html tag: input.

Overrides:
getTag in class AbstractControl
Returns:
this controls html tag
See Also:
AbstractControl.getTag()

getFileItem

public 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

getControlSizeEst

public int getControlSizeEst()
Description copied from class: AbstractControl
Return the estimated rendered control size in characters.

Overrides:
getControlSizeEst in class AbstractControl
Returns:
the estimated rendered control size in characters
See Also:
AbstractControl.getControlSizeEst()

render

public void render(HtmlStringBuffer buffer)
Render the HTML representation of the FileField.

Specified by:
render in interface 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