CreateAction not working in Cuba 7.0

I want to initialize values for the editor screen using the CreateAction in the StandardLookup. But i’m getting the following error in the browser page.

IllegalArgumentException: Can not set com.haulmont.cuba.gui.components.actions.CreateAction field.

Hi,

If something doesn’t work, please be more specific about what you have already tried to do. At least attach a code snippet how you customize the EditAction.

Regards,
Gleb

I’m using the following Code

@UiController("enterprise_ExtFileDescriptor.browse")
@UiDescriptor("ext-file-descriptor-browse.xml")
@LookupComponent("extFileDescriptorsTable")
@LoadDataBeforeShow
public class ExtFileDescriptorBrowse extends StandardLookup<ExtFileDescriptor> {

    @Named("extFileDescriptorsTable.create")
    private CreateAction createAction;

    @Override
    protected void initActions(InitEvent event) {
        createAction.setInitialValues(ParamsMap.of("grade", grade));
    }
}

I’m getting the following error:

IllegalArgumentException: Can not set com.haulmont.cuba.gui.components.actions.CreateAction field
 com.ipectechnologies.projectnow.enterprise.web.extfiledescriptor.ExtFileDescriptorBrowse.createAction 
to com.haulmont.cuba.gui.actions.list.CreateAction

The reason why you got the exception is that you have an incorrect import of CreateAction.

It appears that you have com.haulmont.cuba.gui.components.actions.CreateAction instead of com.haulmont.cuba.gui.actions.list.CreateAction.

In order to define initial values for the new CreateAction you need to subscribe on ActionPerformedEvent and open editor with initializer:

@UiController("sys_FileDescriptor.browse")
@UiDescriptor("file-descriptor-browse.xml")
@LookupComponent("fileDescriptorsTable")
@LoadDataBeforeShow
public class FileDescriptorBrowse extends StandardLookup<FileDescriptor> {
    @Inject
    private Table<FileDescriptor> fileDescriptorsTable;
    @Inject
    private ScreenBuilders screenBuilders;

    @Subscribe("fileDescriptorsTable.create")
    protected void onFileDescriptorsTableCreate(Action.ActionPerformedEvent event) {
        Screen editor = screenBuilders.editor(fileDescriptorsTable)
                .newEntity()
                .withInitializer(fileDescriptor -> {
                    // Init a new Entity
                })
                .withOpenMode(OpenMode.DIALOG)
                .build();
        editor.show();
    }
}