Class FileField
- java.lang.Object
-
- org.openidentityplatform.openam.click.control.AbstractControl
-
- org.openidentityplatform.openam.click.control.Field
-
- org.openidentityplatform.openam.click.control.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'>.
The FileField control uses the Jakarta Commons FileUpload library to provide file processing functionality.Example File Field <input type='file' value=''/> You can control the
maximum request sizeandmaximum file sizeby configuringCommonsFileUploadService.Note Browsers enforce the JavaScript
valueproperty 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 Summary
Fields Modifier and Type Field Description protected org.apache.commons.fileupload.FileItemfileItemThe DefaultFileItem after processing a file upload request.protected intsizeThe text field size attribute.protected static StringVALIDATE_FILEFIELD_FUNCTIONThe field validation JavaScript function template.-
Fields inherited from class org.openidentityplatform.openam.click.control.Field
disabled, error, focus, form, help, label, labelStyle, labelStyleClass, parentStyleClassHint, parentStyleHint, readonly, required, tabindex, title, trim, validate, value
-
Fields inherited from class org.openidentityplatform.openam.click.control.AbstractControl
actionListener, attributes, behaviors, headElements, listener, listenerMethod, messages, name, parent, styles
-
-
Constructor Summary
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbindRequestValue()Set thefileItemproperty from the multi-part form data submission.intgetControlSizeEst()Return the estimated rendered control size in characters.org.apache.commons.fileupload.FileItemgetFileItem()Return the FileItem after processing the request, or null otherwise.intgetSize()Return the field size.StringgetTag()Return the FileField's html tag:input.StringgetType()Return the input type: 'file'.StringgetValidationJavaScript()Return the FileField JavaScript client side validation function.booleanonProcess()Overrides onProcess to useContext.getFileItem(String).voidrender(HtmlStringBuffer buffer)Render the HTML representation of the FileField.voidsetSize(int size)Set the field size.voidvalidate()Validate the FileField request submission.-
Methods inherited from class org.openidentityplatform.openam.click.control.Field
getError, getErrorLabel, getFocus, getFocusJavaScript, getForm, getHelp, getId, getLabel, getLabelStyle, getLabelStyleClass, getParentStyleClassHint, getParentStyleHint, getRequestValue, getState, getTabIndex, getTextAlign, getTitle, getValidate, getValue, getValueObject, getWidth, isDisabled, isHidden, isReadonly, isRequired, isTrim, isValid, removeState, renderTagBegin, restoreState, saveState, setDisabled, setError, setErrorMessage, setErrorMessage, setFocus, setForm, setHelp, setLabel, setLabelStyle, setLabelStyleClass, setListener, setParent, setParentStyleClassHint, setParentStyleHint, setReadonly, setRequired, setState, setTabIndex, setTextAlign, setTitle, setTrim, setValidate, setValue, setValueObject, setWidth
-
Methods inherited from class org.openidentityplatform.openam.click.control.AbstractControl
addBehavior, addStyleClass, appendAttributes, dispatchActionEvent, getActionListener, getAttribute, getAttributes, getBehaviors, getContext, getHeadElements, getHtmlImports, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasBehaviors, hasStyles, isAjaxTarget, onDeploy, onDestroy, onInit, onRender, removeBehavior, removeStyleClass, renderTagEnd, setActionListener, setAttribute, setId, setName, setStyle, toString
-
-
-
-
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 fieldrequired- 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 fieldlabel- 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 fieldlabel- the label of the fieldrequired- 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 fieldlabel- the label of the fieldsize- 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:
getTagin classAbstractControl- 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
FileItemafter 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:
getValidationJavaScriptin classField- Returns:
- the field JavaScript client side validation function
-
bindRequestValue
public void bindRequestValue()
Set thefileItemproperty from the multi-part form data submission.- Overrides:
bindRequestValuein classField
-
getControlSizeEst
public int getControlSizeEst()
Description copied from class:AbstractControlReturn the estimated rendered control size in characters.- Overrides:
getControlSizeEstin classAbstractControl- Returns:
- the estimated rendered control size in characters
- See Also:
AbstractControl.getControlSizeEst()
-
onProcess
public boolean onProcess()
Overrides onProcess to useContext.getFileItem(String).- Specified by:
onProcessin interfaceorg.openidentityplatform.openam.click.Control- Overrides:
onProcessin classField- 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:
renderin interfaceorg.openidentityplatform.openam.click.Control- Overrides:
renderin classAbstractControl- Parameters:
buffer- the specified buffer to render the control's output to- See Also:
AbstractControl.toString()
-
-