Class FileStorageUploadField

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.AbstractField<C,V>
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:
  • Field Details

    • applicationContext

      protected org.springframework.context.ApplicationContext applicationContext
    • temporaryStorage

      protected TemporaryStorage temporaryStorage
    • fileStorageLocator

      protected FileStorageLocator fileStorageLocator
    • downloader

      protected Downloader downloader
    • notifications

      protected Notifications notifications
    • messages

      protected Messages messages
    • multipartPropertiesProvider

      protected org.springframework.beans.factory.ObjectProvider<org.springframework.boot.autoconfigure.web.servlet.MultipartProperties> multipartPropertiesProvider
    • fieldDelegate

    • fileStorage

      protected FileStorage fileStorage
  • Constructor Details

    • FileStorageUploadField

      public FileStorageUploadField()
  • Method Details

    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
      Throws:
      org.springframework.beans.BeansException
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception
    • autowireDependencies

      protected void autowireDependencies()
    • initComponent

      protected void initComponent()
    • createFieldDelegate

      protected FieldDelegate<FileStorageUploadField,FileRef,FileRef> createFieldDelegate()
    • isInvalid

      public boolean isInvalid()
      Specified by:
      isInvalid in interface com.vaadin.flow.component.HasValidation
    • getRequiredMessage

      @Nullable public String getRequiredMessage()
      Specified by:
      getRequiredMessage in interface HasRequired
    • setRequiredMessage

      public void setRequiredMessage(@Nullable String requiredMessage)
      Specified by:
      setRequiredMessage in interface HasRequired
    • addValidator

      public com.vaadin.flow.shared.Registration addValidator(Validator<? super FileRef> validator)
      Specified by:
      addValidator in interface SupportsValidation<FileRef>
    • executeValidators

      public void executeValidators() throws ValidationException
      Specified by:
      executeValidators in interface SupportsValidation<FileRef>
      Throws:
      ValidationException
    • setInvalid

      public void setInvalid(boolean invalid)
      Description copied from interface: SupportsValidation
      Sets 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:
      setInvalid in interface com.vaadin.flow.component.HasValidation
      Specified by:
      setInvalid in interface SupportsValidation<FileRef>
      Parameters:
      invalid - whether field should be invalid
    • getValueSource

      @Nullable public ValueSource<FileRef> getValueSource()
      Specified by:
      getValueSource in interface SupportsValueSource<FileRef>
    • setValueSource

      public void setValueSource(@Nullable ValueSource<FileRef> valueSource)
      Specified by:
      setValueSource in interface SupportsValueSource<FileRef>
    • setStatusChangeHandler

      public void setStatusChangeHandler(@Nullable Consumer<SupportsStatusChangeHandler.StatusContext<FileStorageUploadField>> handler)
      Description copied from interface: SupportsStatusChangeHandler
      Sets a callback to be used to handle component status changes, e.g. validation messages set by HasValidation.setErrorMessage(String).
      Specified by:
      setStatusChangeHandler in interface SupportsStatusChangeHandler<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 MultipartProperties is available, the default value will be set from MultipartProperties.getMaxFileSize() that is equal to 1Mb. To increase maximum file size for all fields in the application use MultipartProperties.getMaxFileSize() property.

      Overrides:
      setMaxFileSize in class AbstractSingleUploadField<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:
      addFileUploadSucceededListener in class AbstractSingleUploadField<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:
      onSucceededEvent in class AbstractSingleUploadField<FileStorageUploadField,FileRef>
    • saveFile

      protected void saveFile(com.vaadin.flow.component.upload.SucceededEvent event)
    • generateFileName

      protected String generateFileName()
      Overrides:
      generateFileName in class JmixFileStorageUploadField<FileStorageUploadField,FileRef>
    • getDefaultUploadText

      protected String getDefaultUploadText()
      Overrides:
      getDefaultUploadText in class JmixFileStorageUploadField<FileStorageUploadField,FileRef>
    • checkFileStorageInitialized

      protected void checkFileStorageInitialized()
    • onFileNameClick

      protected void onFileNameClick(com.vaadin.flow.component.ClickEvent<?> clickEvent)
    • handleJmixUploadInternalError

      protected void handleJmixUploadInternalError(String fileName)
      Overrides:
      handleJmixUploadInternalError in class AbstractSingleUploadField<FileStorageUploadField,FileRef>
    • showUploadErrorNotification

      protected void showUploadErrorNotification(String fileName)
    • valueEquals

      protected boolean valueEquals(FileRef value1, FileRef value2)
      Overrides:
      valueEquals in class com.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:
      onFileRejectedEvent in class AbstractSingleUploadField<FileStorageUploadField,FileRef>
    • onFailedEvent

      protected void onFailedEvent(com.vaadin.flow.component.upload.FailedEvent event)
      Overrides:
      onFailedEvent in class AbstractSingleUploadField<FileStorageUploadField,FileRef>
    • deleteTempFile

      protected void deleteTempFile()
    • applyI18nDefaults

      protected void applyI18nDefaults()
    • onAttach

      protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
      Overrides:
      onAttach in class com.vaadin.flow.component.Component