With fileStoragePutMode="MANUAL", no ValueChange events are sent

Jmix version: 1.1.2
Jmix Studio plugin version: 1.1.4-213
IntelliJ IDEA 2021.3 CE - Build #IC-213.5744.223, built on November 27, 2021
Operating System: macOS 12.1 (21C52)
File System: Case-Sensitive Journaled HFS+ (APFS)
Datebase: PostgreSQL 13

Hi Everyone

For your information, as soon as I set the fileStoragePutMode of my fileStorageUpload component to MANUAL, the ValueChange events are no longer sent to my listener during the file upload or when clearing the component with its clear() method.

Attached you will find a small demo where this behavior can be reproduced:

Anonym.zip (80.1 KB)

Can you please confirm whether this is a bug or an undocumented behavior. Thanks in advance.

Best regards
Chris

Hi @chrisbeaham

Thanks for your attention, it’s not a bug.
In Jmix we use FileRef instead of FileDescriptor and FileRef can be obtained only after uploading a file to the storage.

We have created a Github ticket for our documentation.

Regards,
Nadezhda.

@n.shatalova

Hello Nadezhda

Thank you for the feedback and your efforts. I understand the new usage of the FileRef and have already refactored all of my code to use it and I can sucessfully upload and store various file types. (Konstantin originally advised me to use the MANUAL mode in a separate post.) But I would still expect to receive a ValueChange event when I call the clear() method, completely independent of whether the mode is set to IMMEDIATE or MANUAL; my file had already loaded.

I can refactor my code again to directly call my clean-up code after calling the clear() method but that feels wrong.

Best regards
Chris

Hi, @chrisbeaham

The “value” of the fileStorageUpload is FileRef (not a file itself). So when you’re using the MANUAL mode and upload a file, the value remains empty until you set it manually after putting the file into the storage. But if you call the clear() method before the file is loaded into the storage you actually don’t change the value (it was null and clear() method sets it to null again), that’s why ValueChangeEvent does not happen. So the described behaviour looks correct.

On the other hand, I understand your point, and I think it’d be reasonable to produce a separate event of clearing the uploaded file (for example, AfterValueClearEvent which is sent after user clicks the “clear” button). We have created a GitHub issue.

At this moment, I think its fine to perform your clean-up code after calling the clear() method.

Regards,
Gleb

@shalyganov @n.shatalova

Hello Gleb

Thank you for the further information and also for your efforts. Since the clear() method clears the file name of the FileStorageUpload component, I expected the ValueChangeListener to also be called. However, it is my mistake that I am thinking of the file name in combination with the component’s FileRef value. I do not actually use the component’s FileRef value.

In my application I put the uploaded file into storage with the following code within my FileUploadSucceedListener method:

FileRef newAudioFileRef = temporaryStorage.putFileIntoStorage(myFileStorageUpload.getFileId(), event.getFileName());

but I do not call myFileStorageUpload.setValue(newAudioFileRef) to save the new FileRef to this screen component because I store this reference in an entity so that it persists when exiting the screen. I do not need to put it into the screen component.

I can explicitly use setValue() so that the events are triggered for both the upload and the clear(); that is not a problem. Therefore, I believe that an additional description in the documentation, as noted by Nadezhda in her comment, might be the solution for everyone. That’s up to you and the team. Thanks again to both of you.

Best regards
Chris

1 Like