Package io.jmix.flowui.component.upload
Class FileStorageUploadField
java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.AbstractField<C,V>
io.jmix.flowui.kit.component.upload.AbstractSingleUploadField<C,V>
io.jmix.flowui.kit.component.upload.JmixFileStorageUploadField<FileStorageUploadField,FileRef>
io.jmix.flowui.component.upload.FileStorageUploadField
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasEnabled,com.vaadin.flow.component.HasHelper,com.vaadin.flow.component.HasLabel,com.vaadin.flow.component.HasSize,com.vaadin.flow.component.HasStyle,com.vaadin.flow.component.HasValidation,com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<FileStorageUploadField,,FileRef>, FileRef> com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<FileStorageUploadField,,FileRef>, FileRef> com.vaadin.flow.component.shared.HasTooltip,HasRequired,SupportsStatusChangeHandler<FileStorageUploadField>,SupportsValidation<FileRef>,SupportsValueSource<FileRef>,Serializable,org.springframework.beans.factory.Aware,org.springframework.beans.factory.InitializingBean,org.springframework.context.ApplicationContextAware
public class FileStorageUploadField
extends JmixFileStorageUploadField<FileStorageUploadField,FileRef>
implements SupportsValueSource<FileRef>, SupportsValidation<FileRef>, HasRequired, SupportsStatusChangeHandler<FileStorageUploadField>, org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.InitializingBean
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField
com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C extends com.vaadin.flow.component.Component,V extends Object> Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
com.vaadin.flow.component.HasValue.ValueChangeEvent<V extends Object>, com.vaadin.flow.component.HasValue.ValueChangeListener<E extends com.vaadin.flow.component.HasValue.ValueChangeEvent<?>>Nested classes/interfaces inherited from interface io.jmix.flowui.component.SupportsStatusChangeHandler
SupportsStatusChangeHandler.StatusContext<C extends com.vaadin.flow.component.Component> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.springframework.context.ApplicationContextprotected Downloaderprotected FieldDelegate<FileStorageUploadField,FileRef, FileRef> protected FileStorageprotected FileStorageLocatorprotected Messagesprotected org.springframework.beans.factory.ObjectProvider<org.springframework.boot.autoconfigure.web.servlet.MultipartProperties>protected Notificationsprotected TemporaryStorageFields inherited from class io.jmix.flowui.kit.component.upload.JmixFileStorageUploadField
fileStorageName, fileStoragePutModeFields inherited from class io.jmix.flowui.kit.component.upload.AbstractSingleUploadField
CLEAR_COMPONENT_ARIA_LABEL, CLEAR_COMPONENT_CLASS_NAME, clearButtonVisible, clearComponent, content, FILE_NAME_COMPONENT_CLASS_NAME, FILE_NAME_COMPONENT_EMPTY_CLASS_NAME, FILE_NOT_SELECTED, fileNameComponent, fileNameVisible, fileNotSelectedText, INPUT_CONTAINER_CLASS_NAME, internalValue, NO_MARGIN_THEME, UPLOAD, uploadButton, uploadTextFields inherited from interface io.jmix.flowui.component.HasRequired
PROPERTY_REQUIREDFields inherited from interface io.jmix.flowui.component.SupportsValidation
PROPERTY_ERROR_MESSAGE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncom.vaadin.flow.shared.RegistrationaddFileUploadSucceededListener(com.vaadin.flow.component.ComponentEventListener<FileUploadSucceededEvent<FileStorageUploadField>> listener) Adds a succeeded listener that is informed on upload succeeded.com.vaadin.flow.shared.RegistrationaddValidator(Validator<? super FileRef> validator) voidprotected voidprotected voidattachValueChangeListener(com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<FileStorageUploadField, FileRef>> listener) protected voidprotected voidprotected FieldDelegate<FileStorageUploadField,FileRef, FileRef> protected voidvoidprotected Stringprotected Stringprotected voidhandleJmixUploadInternalError(String fileName) protected voidbooleanprotected voidonAttach(com.vaadin.flow.component.AttachEvent attachEvent) protected voidonFailedEvent(com.vaadin.flow.component.upload.FailedEvent event) protected voidonFileNameClick(com.vaadin.flow.component.ClickEvent<?> clickEvent) protected voidonFileRejectedEvent(com.vaadin.flow.component.upload.FileRejectedEvent event) protected voidonSucceededEvent(com.vaadin.flow.component.upload.SucceededEvent event) protected voidonValueChange(com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<FileStorageUploadField, FileRef> event) protected voidsaveFile(com.vaadin.flow.component.upload.SucceededEvent event) voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) voidsetInvalid(boolean invalid) Sets invalid state to the field considering result of field validation.voidsetMaxFileSize(int maxFileSize) Specify the maximum file size in bytes allowed to upload.voidsetRequiredMessage(String requiredMessage) voidsetStatusChangeHandler(Consumer<SupportsStatusChangeHandler.StatusContext<FileStorageUploadField>> handler) Sets a callback to be used to handle component status changes, e.g.voidsetValueSource(ValueSource<FileRef> valueSource) protected voidshowUploadErrorNotification(String fileName) protected booleanvalueEquals(FileRef value1, FileRef value2) Methods inherited from class io.jmix.flowui.kit.component.upload.JmixFileStorageUploadField
getFileStorageName, getFileStoragePutMode, setFileStorageName, setFileStoragePutModeMethods inherited from class io.jmix.flowui.kit.component.upload.AbstractSingleUploadField
addClassNames, addFileUploadFailedListener, addFileUploadFileRejectedListener, addFileUploadFinishedListener, addFileUploadProgressListener, addFileUploadStartedListener, addThemeNames, addValueChangeListener, attachContent, attachUploadEvents, createClearComponent, createContentComponent, createFileNameComponent, createUploadButtonComponent, createUploadComponent, createUploadReceiver, getAcceptedFileTypes, getClearButtonAriaLabel, getContent, getEmptyValue, getFileNotSelectedText, getI18n, getMaxFileSize, getUploadIcon, getUploadText, getValue, initClearComponent, initContentComponent, initFileNameComponent, initUploadButtonComponent, initUploadComponent, isClearButtonVisible, isDropAllowed, isFileNameVisible, onClearButtonClick, onFinishedEvent, onJmixUploadInternalError, onProgressEvent, onStartedEvent, removeClassNames, setAcceptedFileTypes, setClearButtonAriaLabel, setClearButtonVisible, setComponentAriaLabel, setComponentClickListener, setComponentEnabled, setComponentText, setDropAllowed, setEnabled, setFileNameVisible, setFileNotSelectedText, setI18n, setInternalValue, setInternalValue, setPresentationValue, setReadOnly, setUploadIcon, setUploadText, setValue, updateComponentsVisibilityMethods inherited from class com.vaadin.flow.component.AbstractField
isEmpty, setModelValueMethods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabledMethods inherited from interface com.vaadin.flow.component.HasHelper
getHelperComponent, getHelperText, setHelperComponent, setHelperTextMethods inherited from interface com.vaadin.flow.component.HasLabel
getLabel, setLabelMethods inherited from interface io.jmix.flowui.component.HasRequired
isRequired, setRequiredMethods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.shared.HasTooltip
getTooltip, setTooltipTextMethods inherited from interface com.vaadin.flow.component.HasValue
clear, getOptionalValueMethods inherited from interface com.vaadin.flow.component.HasValueAndElement
isReadOnly, isRequiredIndicatorVisible, setRequiredIndicatorVisibleMethods inherited from interface io.jmix.flowui.component.SupportsValidation
getErrorMessage, setErrorMessage
-
Field Details
-
applicationContext
protected org.springframework.context.ApplicationContext applicationContext -
temporaryStorage
-
fileStorageLocator
-
downloader
-
notifications
-
messages
-
multipartPropertiesProvider
protected org.springframework.beans.factory.ObjectProvider<org.springframework.boot.autoconfigure.web.servlet.MultipartProperties> multipartPropertiesProvider -
fieldDelegate
-
fileStorage
-
-
Constructor Details
-
FileStorageUploadField
public FileStorageUploadField()
-
-
Method Details
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception
-
autowireDependencies
protected void autowireDependencies() -
initComponent
protected void initComponent() -
createFieldDelegate
-
isInvalid
public boolean isInvalid()- Specified by:
isInvalidin interfacecom.vaadin.flow.component.HasValidation
-
getRequiredMessage
- Specified by:
getRequiredMessagein interfaceHasRequired
-
setRequiredMessage
- Specified by:
setRequiredMessagein interfaceHasRequired
-
addValidator
- Specified by:
addValidatorin interfaceSupportsValidation<FileRef>
-
executeValidators
- Specified by:
executeValidatorsin interfaceSupportsValidation<FileRef>- Throws:
ValidationException
-
setInvalid
public void setInvalid(boolean invalid) Description copied from interface:SupportsValidationSets invalid state to the field considering result of field validation.- Invalid - false and validation passed - false = field is invalid
- Invalid - false and validation passed - true = field is valid
- Invalid - true and validation passed - false = field is invalid
- Invalid - true and validation passed - true = field is invalid
- Specified by:
setInvalidin interfacecom.vaadin.flow.component.HasValidation- Specified by:
setInvalidin interfaceSupportsValidation<FileRef>- Parameters:
invalid- whether field should be invalid
-
getValueSource
- Specified by:
getValueSourcein interfaceSupportsValueSource<FileRef>
-
setValueSource
- Specified by:
setValueSourcein interfaceSupportsValueSource<FileRef>
-
setStatusChangeHandler
public void setStatusChangeHandler(@Nullable Consumer<SupportsStatusChangeHandler.StatusContext<FileStorageUploadField>> handler) Description copied from interface:SupportsStatusChangeHandlerSets a callback to be used to handle component status changes, e.g. validation messages set byHasValidation.setErrorMessage(String).- Specified by:
setStatusChangeHandlerin interfaceSupportsStatusChangeHandler<FileStorageUploadField>- Parameters:
handler- a handler to set
-
setMaxFileSize
public void setMaxFileSize(int maxFileSize) Specify the maximum file size in bytes allowed to upload. Notice that it is a client-side constraint, which will be checked before sending the request.Note if
MultipartPropertiesis available, the default value will be set fromMultipartProperties.getMaxFileSize()that is equal to 1Mb. To increase maximum file size for all fields in the application useMultipartProperties.getMaxFileSize()property.- Overrides:
setMaxFileSizein classAbstractSingleUploadField<FileStorageUploadField,FileRef> - Parameters:
maxFileSize- the maximum file size in bytes- See Also:
-
Upload.setMaxFileSize(int)MultipartProperties.getMaxFileSize()MultipartProperties.getMaxRequestSize()
-
addFileUploadSucceededListener
public com.vaadin.flow.shared.Registration addFileUploadSucceededListener(com.vaadin.flow.component.ComponentEventListener<FileUploadSucceededEvent<FileStorageUploadField>> listener) Adds a succeeded listener that is informed on upload succeeded.For instance, if component has
FileStoragePutMode.MANUAL, we can handle the uploading, like the following:manuallyControlledField.addFileUploadSucceededListener(event -> { FileTemporaryStorageBuffer receiver = event.getReceiver(); File file = temporaryStorage.getFile(receiver.getFileData().getFileInfo().getId()); if (file != null) { notifications.create("File is uploaded to temporary storage at " + file.getAbsolutePath()) .show(); } FileRef fileRef = temporaryStorage.putFileIntoStorage(receiver.getFileData().getFileInfo().getId(), event.getFileName()); manuallyControlledField.setValue(fileRef); notifications.create("Uploaded file: " + event.getFileName()) .show(); });- Overrides:
addFileUploadSucceededListenerin classAbstractSingleUploadField<FileStorageUploadField,FileRef> - Parameters:
listener- listener to add- Returns:
- registration for removal of listener
- See Also:
-
onSucceededEvent
protected void onSucceededEvent(com.vaadin.flow.component.upload.SucceededEvent event) - Overrides:
onSucceededEventin classAbstractSingleUploadField<FileStorageUploadField,FileRef>
-
saveFile
protected void saveFile(com.vaadin.flow.component.upload.SucceededEvent event) -
generateFileName
- Overrides:
generateFileNamein classJmixFileStorageUploadField<FileStorageUploadField,FileRef>
-
getDefaultUploadText
- Overrides:
getDefaultUploadTextin classJmixFileStorageUploadField<FileStorageUploadField,FileRef>
-
checkFileStorageInitialized
protected void checkFileStorageInitialized() -
onFileNameClick
protected void onFileNameClick(com.vaadin.flow.component.ClickEvent<?> clickEvent) -
handleJmixUploadInternalError
- Overrides:
handleJmixUploadInternalErrorin classAbstractSingleUploadField<FileStorageUploadField,FileRef>
-
showUploadErrorNotification
-
valueEquals
- Overrides:
valueEqualsin classcom.vaadin.flow.component.AbstractField<FileStorageUploadField,FileRef>
-
attachValueChangeListener
protected void attachValueChangeListener(com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<FileStorageUploadField, FileRef>> listener) -
onValueChange
protected void onValueChange(com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<FileStorageUploadField, FileRef> event) -
onFileRejectedEvent
protected void onFileRejectedEvent(com.vaadin.flow.component.upload.FileRejectedEvent event) - Overrides:
onFileRejectedEventin classAbstractSingleUploadField<FileStorageUploadField,FileRef>
-
onFailedEvent
protected void onFailedEvent(com.vaadin.flow.component.upload.FailedEvent event) - Overrides:
onFailedEventin classAbstractSingleUploadField<FileStorageUploadField,FileRef>
-
deleteTempFile
protected void deleteTempFile() -
applyI18nDefaults
protected void applyI18nDefaults() -
onAttach
protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent) - Overrides:
onAttachin classcom.vaadin.flow.component.Component
-