IllegalStateException: CreateAction target is not set

Hello,

Clicking the button takes an action, but it returns this error. Below is the screenshot and code.
Version: Jmix 1.5 flowui
Screenshot 2023-03-24 at 20.15.33

    @Subscribe
    public void onInit(InitEvent event) {
        CreateAction<User> registerPerson = new CreateAction<>();
        registerPerson.setOpenMode(OpenMode.NAVIGATION);
        registerPerson.setViewClass(SignupDetailsView.class);
        registerPerson.setText(messageBundle.getMessage("continue"));
        selectPersonTypeButton.setAction(registerPerson);
    }

Hello!

CreateAction is an action that supposed to be used in DataGrid (or in general in components based on ListDataComponent interface). It requires to know to which component action is assigned. So you see an error if “target” (DataGrid) is not set.

If you want to open the “detail” View to create a new instance of some entity, use ViewNavigators :

@Autowired
ViewNavigators viewNavigators;

viewNavigators.detailView(MyEntity.class)
        .newEntity()
        .withViewClass(MyEntityDetailsView.class)
        .navigate();
1 Like

Thank you for your solution.

Hi, how do i use an action on a detail page? I want to make a ResetPassword button on a profile page, which will call the resetPassword action for the logged in user.

Hi,

You can use actions in Detail views the same way as for List views:

The sec_resetPassword action that you can see in user-list-view.xml can be used only inside a DataGrid. But you can copy the logic of this action to build a predefined ResetPasswordView. For instance:

@Autowired
private DialogWindows dialogWindows;

@Subscribe(id = "resetPasswordBtn", subject = "clickListener")
public void onResetPasswordBtnClick(final ClickEvent<JmixButton> event) {
    DialogWindow<ResetPasswordView> dialog = dialogWindows
            .view(this, ResetPasswordView.class)
            .build();
    ResetPasswordView view = dialog.getView();
    view.setUsers(selectedUser); // or use CurrentAuthentication or CurrentUserSubstitution
    dialog.open();
}

If you want a custom dialog, inject UserManager bean. It has resetPasswords() and changePassword() methods.

1 Like