Class MultiFileUploadField
- java.lang.Object
-
- org.apache.wicket.Component
-
- org.apache.wicket.MarkupContainer
-
- org.apache.wicket.markup.html.WebMarkupContainer
-
- org.apache.wicket.markup.html.form.LabeledWebMarkupContainer
-
- org.apache.wicket.markup.html.form.FormComponent<T>
-
- org.apache.wicket.markup.html.form.FormComponentPanel<Collection<FileUpload>>
-
- org.apache.wicket.markup.html.form.upload.MultiFileUploadField
-
- All Implemented Interfaces:
Serializable
,Iterable<Component>
,IEventSink
,IEventSource
,IFeedbackContributor
,IConverterLocator
,IGenericComponent<Collection<FileUpload>,FormComponent<Collection<FileUpload>>>
,IMetadataContext<Serializable,Component>
,IQueueRegion
,IFormModelUpdateListener
,IFormVisitorParticipant
,ILabelProvider<String>
,IHeaderContributor
,IRequestableComponent
,IHierarchical<Component>
,IClusterable
public class MultiFileUploadField extends FormComponentPanel<Collection<FileUpload>>
Form component that allows the user to select multiple files to upload via a single <input type="file"/> field. Notice that this component clears its model at the end of the request, so the uploaded files MUST be processed within the request they were uploaded. Uses javascript implementation from http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/ For customizing caption text seeRESOURCE_LIMITED
andRESOURCE_UNLIMITED
For an example of styling using CSS see the upload example in wicket-examples- Author:
- Igor Vaynberg (ivaynberg)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static ResourceReference
JS
static String
MAGIC_SEPARATOR
static String
RESOURCE_LIMITED
Resource key used to retrieve caption message for when a limit on the number of uploads is specified.static String
RESOURCE_UNLIMITED
Resource key used to retrieve caption message for when no limit on the number of uploads is specified.static int
UNLIMITED
Represents an unlimited max count of uploads-
Fields inherited from class org.apache.wicket.markup.html.form.FormComponent
FLAG_CONVERT_EMPTY_INPUT_STRING_TO_NULL, VALUE_SEPARATOR
-
Fields inherited from class org.apache.wicket.Component
ENABLE, FLAG_INITIALIZED, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER, RFLAG_CONTAINER_DEQUEING, RFLAG_CONTAINER_HAS_REMOVALS
-
-
Constructor Summary
Constructors Constructor Description MultiFileUploadField(String id)
ConstructorMultiFileUploadField(String id, int max)
ConstructorMultiFileUploadField(String id, IModel<? extends Collection<FileUpload>> model)
ConstructorMultiFileUploadField(String id, IModel<? extends Collection<FileUpload>> model, int max)
ConstructorMultiFileUploadField(String id, IModel<? extends Collection<FileUpload>> model, int max, boolean useMultipleAttr)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Collection<FileUpload>
convertValue(String[] value)
Subclasses should overwrite this if the conversion is not done through the type field and theIConverter
.protected boolean
forceCloseStreamsOnDetach()
The FileUploadField will close any input streams you have opened in its FileUpload by default.String[]
getInputAsArray()
Gets the request parameters for this component as strings.boolean
isMultiPart()
protected void
onBeforeRender()
Called on all visible components before any component is rendered.protected void
onComponentTag(ComponentTag tag)
Processes the component tag.protected void
onDetach()
Sets the temporary converted input value to null.void
renderHead(IHeaderResponse response)
Render to the web response whatever the component wants to contribute to the head section.void
updateModel()
SeeFormComponent.updateCollectionModel(FormComponent)
for details on how the model is updated.-
Methods inherited from class org.apache.wicket.markup.html.form.FormComponentPanel
checkRequired, clearInput, newMarkupSourcingStrategy
-
Methods inherited from class org.apache.wicket.markup.html.form.FormComponent
add, add, convertInput, error, getConvertedInput, getDefaultLabel, getDefaultLabel, getForm, getInput, getInputName, getModelValue, getParameterValues, getRawInput, getType, getValidatorKeyPrefix, getValidators, getValue, hasRawInput, inputAsInt, inputAsInt, inputAsIntArray, inputChanged, internalOnModelChanged, invalid, isInputNullable, isRequired, isValid, newValidatable, newValidationError, onDisabled, onInvalid, onValid, processChildren, processInput, remove, reportRequiredError, setConvertedInput, setLabel, setModelValue, setRequired, setType, shouldTrimInput, trim, updateAutoLabels, updateAutoLabels, updateCollectionModel, valid, validate, validateRequired, validateValidators, visitComponentsPostOrder, visitFormComponentsPostOrder
-
Methods inherited from class org.apache.wicket.markup.html.form.LabeledWebMarkupContainer
getLabel
-
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getWebApplication, getWebPage, getWebRequest, getWebResponse, getWebSession
-
Methods inherited from class org.apache.wicket.MarkupContainer
add, addDequeuedComponent, addOrReplace, autoAdd, canDequeueTag, contains, dequeue, dequeue, dequeuePreamble, findChildComponent, findComponentToDequeue, get, getAssociatedMarkup, getAssociatedMarkupStream, getMarkup, getMarkupType, getRegionMarkup, internalAdd, internalInitialize, iterator, iterator, newDequeueContext, onComponentTagBody, onInitialize, onRender, queue, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderAssociatedMarkup, renderNext, replace, setDefaultModel, size, stream, streamChildren, toString, toString, visitChildren, visitChildren
-
Methods inherited from class org.apache.wicket.Component
add, addStateChange, beforeRender, canCallListener, canCallListenerAfterExpiry, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, clearOriginalDestination, configure, continueToOriginalDestination, createConverter, debug, detach, detachModel, detachModels, determineVisibility, error, exceptionMessage, fatal, findMarkupStream, findPage, findParent, findParentWithAssociatedMarkup, getAjaxRegionMarkupId, getApplication, getBehaviorById, getBehaviorId, getBehaviors, getBehaviors, getClassRelativePath, getConverter, getDefaultModel, getDefaultModelObject, getDefaultModelObjectAsString, getDefaultModelObjectAsString, getEscapeModelStrings, getFeedbackMessages, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkup, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdFromMarkup, getMarkupIdImpl, getMarkupSourcingStrategy, getMarkupTag, getMetaData, getModelComparator, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getRequestFlag, getResponse, getSession, getSizeInBytes, getStatelessHint, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, initModel, internalRenderComponent, internalRenderHead, isActionAuthorized, isAuto, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isInitialized, isRenderAllowed, isRendering, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, markRendering, modelChanged, modelChanging, onAfterRender, onConfigure, onEvent, onModelChanged, onModelChanging, onReAdd, onRemove, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, renderPart, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, send, setAuto, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setIgnoreAttributeModifier, setMarkup, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setParent, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, success, urlFor, urlFor, urlFor, urlForListener, urlForListener, visitParents, visitParents, warn, wrap
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.wicket.IGenericComponent
getDefaultModel, getDefaultModelObject, getModel, getModelObject, setDefaultModel, setDefaultModelObject, setModel, setModelObject
-
Methods inherited from interface org.apache.wicket.IQueueRegion
dequeue, getRegionMarkup, newDequeueContext
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
UNLIMITED
public static final int UNLIMITED
Represents an unlimited max count of uploads- See Also:
- Constant Field Values
-
RESOURCE_LIMITED
public static final String RESOURCE_LIMITED
Resource key used to retrieve caption message for when a limit on the number of uploads is specified. The limit is represented via ${max} variable. Example: org.apache.wicket.mfu.caption.limited=Files (maximum ${max}):- See Also:
- Constant Field Values
-
RESOURCE_UNLIMITED
public static final String RESOURCE_UNLIMITED
Resource key used to retrieve caption message for when no limit on the number of uploads is specified. Example: org.apache.wicket.mfu.caption.unlimited=Files:- See Also:
- Constant Field Values
-
MAGIC_SEPARATOR
public static final String MAGIC_SEPARATOR
- See Also:
- Constant Field Values
-
JS
public static final ResourceReference JS
-
-
Constructor Detail
-
MultiFileUploadField
public MultiFileUploadField(String id)
Constructor- Parameters:
id
-
-
MultiFileUploadField
public MultiFileUploadField(String id, int max)
Constructor- Parameters:
id
-max
- max number of files a user can upload
-
MultiFileUploadField
public MultiFileUploadField(String id, IModel<? extends Collection<FileUpload>> model)
Constructor- Parameters:
id
-model
-
-
MultiFileUploadField
public MultiFileUploadField(String id, IModel<? extends Collection<FileUpload>> model, int max)
Constructor- Parameters:
id
-model
-max
- max number of files a user can upload
-
MultiFileUploadField
public MultiFileUploadField(String id, IModel<? extends Collection<FileUpload>> model, int max, boolean useMultipleAttr)
Constructor- Parameters:
id
-model
-max
- max number of files a user can uploaduseMultipleAttr
- true in order to use the new HTML5 "multiple" <input> attribute. It will allow the users to select multiple files at once for multiple times if the browser supports it, otherwise it will work just as before - one file multiple times.
-
-
Method Detail
-
onComponentTag
protected void onComponentTag(ComponentTag tag)
Description copied from class:FormComponent
Processes the component tag.- Overrides:
onComponentTag
in classFormComponentPanel<Collection<FileUpload>>
- Parameters:
tag
- Tag to modify- See Also:
FormComponentPanel.onComponentTag(org.apache.wicket.markup.ComponentTag)
-
onBeforeRender
protected void onBeforeRender()
Description copied from class:Component
Called on all visible components before any component is rendered.NOTE: If you override this, you *must* call super.onBeforeRender() within your implementation. Because this method is responsible for cascading
Changes to the component tree can be made only before calling super.onBeforeRender().Component.onBeforeRender()
call to its children it is strongly recommended that super call is made at the end of the override.- Overrides:
onBeforeRender
in classFormComponent<Collection<FileUpload>>
- See Also:
Component.onBeforeRender()
-
isMultiPart
public boolean isMultiPart()
- Overrides:
isMultiPart
in classFormComponent<Collection<FileUpload>>
- Returns:
- True if this component encodes data in a multipart form submit
-
renderHead
public void renderHead(IHeaderResponse response)
Description copied from class:Component
Render to the web response whatever the component wants to contribute to the head section.- Specified by:
renderHead
in interfaceIHeaderContributor
- Overrides:
renderHead
in classComponent
- Parameters:
response
- Response object
-
getInputAsArray
public String[] getInputAsArray()
Description copied from class:FormComponent
Gets the request parameters for this component as strings.- Overrides:
getInputAsArray
in classFormComponent<Collection<FileUpload>>
- Returns:
- The values in the request for this component
- See Also:
FormComponent.getInputAsArray()
-
convertValue
protected Collection<FileUpload> convertValue(String[] value) throws ConversionException
Description copied from class:FormComponent
Subclasses should overwrite this if the conversion is not done through the type field and theIConverter
. WARNING: this method may be removed in future versions. If conversion fails then a ConversionException should be thrown- Overrides:
convertValue
in classFormComponent<Collection<FileUpload>>
- Parameters:
value
- The value can be the getInput() or through a cookie- Returns:
- The converted value. default returns just the given value
- Throws:
ConversionException
- If input can't be converted
-
updateModel
public void updateModel()
SeeFormComponent.updateCollectionModel(FormComponent)
for details on how the model is updated.- Specified by:
updateModel
in interfaceIFormModelUpdateListener
- Overrides:
updateModel
in classFormComponent<Collection<FileUpload>>
-
onDetach
protected void onDetach()
Description copied from class:FormComponent
Sets the temporary converted input value to null.- Overrides:
onDetach
in classFormComponent<Collection<FileUpload>>
- See Also:
Component.onDetach()
-
forceCloseStreamsOnDetach
protected boolean forceCloseStreamsOnDetach()
The FileUploadField will close any input streams you have opened in its FileUpload by default. If you wish to manage the stream yourself (e.g. you want to use it in another thread) then you can override this method to prevent this behavior.- Returns:
true
if stream should be closed at the end of request
-
-