No action buttons in the External Files lookup screen

Hi…
I am using the FileDescriptor in my Entity with Many to Many Cardinality… In the lookup screen(External files), i cant find the Create, Edit and Remove Action buttons. How to add the action buttons on the lookup window…

Hi,

You can add these actions in your Entity’s edit screen, for example:

<groupBox id="pictureBox"
          caption="msg://com.company.demo.entity/MyEntity.picture">
    <table id="pictureTable"
           height="200px"
           width="100%">
        <actions>
            <action id="add"/>
            <action id="create"/>
            <action id="edit"/>
            <action id="remove"/>
        </actions>
        <columns>
            <column id="name"/>
            <column id="createDate"/>
            <column id="extension"/>
        </columns>
        <rows datasource="pictureDs"/>
        <buttonsPanel>
            <button action="pictureTable.add"/>
            <button action="pictureTable.create"/>
            <button action="pictureTable.edit"/>
            <button action="pictureTable.remove"/>
        </buttonsPanel>
    </table>
</groupBox>

In this case you will be able to open the FileDescriptor’s edit screen directly from your Entity’s edit screen.

Another option: override the lookup screen for FileDescriptor, so that clicking the Add button in the Entity’s edit screen will open the new FileDescriptor lookup screen with all necessary buttons.
An example of web-screens.xml:

<screen-config xmlns="http://schemas.haulmont.com/cuba/screens.xsd">
// all your screens here
    <screen id="demo$MyEntity.edit"
            template="com/company/demo/web/myentity/my-entity-edit.xml"/>
    <screen id="sys$FileDescriptor.lookup"
            template="com/company/demo/web/filedescriptor/file-descriptor-browse.xml"/>
</screen-config>

Thanks @shiryaeva it works, but the file is not storing after the commit… Do i need to add Listener Script to Commit in the Entity? Please help me regarding this…

By default, the file itself is stored in the file storage, and the FileDescriptor instance is stored in the database. Normally, no additional listeners are needed if you use the standard create and edit actions.

If you want to store files in a database as byte arrays, take a look at this sample project.

The Add Action properly stores the FileDescriptor instance in the database, but the Create Action doesn’t stores the FileDescriptor Instance in the database…

Create action creates records in DB as well. Could you share a small sample project to show the problem with saving FileDescriptor instances?

Actually the Problem is, it works well in new sample project… Both Add & create is working (i.e., it saves the file and creates the instance of file descriptor) … But in my main development project the add is working, but the create is not working… Actually the main development project is been migrated from 6.8.x to 6.9…

Migration to 6.9 doesn’t seem to be the reason. Unfortunately, we cannot reproduce your problem. Could you provide more details of your main development project - data model, the code of screen descriptor and controller, and anything that relates to the problem. Thank you.

Sorry for the late reply…

        <datasource id="fileInfoDs"
                    class="com.company.testupload.entity.FileInfo"
                    view="file-view">
            <collectionDatasource id="fileDs"
                                  property="file"/>
        </datasource>
    </dsContext>
    <dialogMode height="600"
                width="800"/>
    <layout expand="windowActions"
            spacing="true">
        <fieldGroup id="fieldGroup"
                    datasource="fileInfoDs">
            <column width="250px">
                <field property="name"/>
            </column>
        </fieldGroup>
        <groupBox id="fileBox"
                  caption="msg://com.company.testupload.entity/FileInfo.file">
            <table id="fileTable"
                   height="200px"
                   width="100%">
                <actions>
                    <action id="add"/>
                    <action id="create"/>
                    <action id="remove"/>
                </actions>
                <columns>
                    <column id="name"/>
                    <column id="createDate"/>
                    <column id="extension"/>
                </columns>
                <rows datasource="fileDs"/>
                <buttonsPanel>
                    <button action="fileTable.create"/>
                    <button action="fileTable.add"/>
                    <button action="fileTable.remove"/>
                </buttonsPanel>
            </table>
        </groupBox>
        <frame id="windowActions"
               screen="editWindowActions"/>

Actually the problem is, I can able to upload the file using create button for the first time. But after saving and re opening the instance, If i try to upload using create button. It upload the files, (even i can see the file in External files screen) but after opening the instance, i cannot able to see the uploaded file in the instance…

Hi,

Here’s the workaround to use CreateAction with many-to-many associations.
Set AfterCommitHandler to add explicitly the newly created instances of FileDescriptor to the collection datasource in FileInfo's editor, for example:

public class FileInfoEdit extends AbstractEditor<FileInfo> {

    @Inject
    private CollectionDatasource<FileDescriptor, UUID> filesDs;
    @Named("fileTable.create")
    private CreateAction fileTableCreate;

    @Override
    public void init(Map<String, Object> params) {
        fileTableCreate.setAfterCommitHandler(entity -> 
                filesDs.addItem((FileDescriptor)entity));
    }
}