Open edit user screen from standard editor or lookup screen

Hi Team ,

Currently we are extending Cuba User Entity to add more additional attributes , Also extending User Edit Screen without adding any changes yet to the screen only entity has some additional fields as below

User Class

@Extends(User.class)
@Entity(name = "vtower_VTowerUser")
public class VTowerUser extends User {
    private static final long serialVersionUID = -5523663666385193410L;

    @NotNull
    @Column(name = "CAN_BE_ASSIGNED_TO_COUNTRY", nullable = false)
    protected Boolean canBeAssignedToCountry = false;

    @NotNull
    @Column(name = "IS_EMPLOYEE", nullable = false)
    protected Boolean isEmployee = false;

    @NotNull
    @Column(name = "IS_GLOBAL_USER", nullable = false)
    protected Boolean isGlobalUser = false;

    @Composition
    @OnDelete(DeletePolicy.CASCADE)
    @OneToMany(mappedBy = "user")
    protected List<OrganizationAssignableUser> assignableOrganizations;

    @Composition
    @OnDelete(DeletePolicy.CASCADE)
    @OneToMany(mappedBy = "user")
    protected List<LegalEntityUser> entities;

    @Composition
    @OnDelete(DeletePolicy.CASCADE)
    @OneToMany(mappedBy = "user")
    protected List<OrganizationUser> organizations;

    @Composition
    @OnDelete(DeletePolicy.CASCADE)
    @OneToMany(mappedBy = "user")
    protected List<CountryUser> countries;

    public List<CountryUser> getCountries() {
        return countries;
    }

    public void setCountries(List<CountryUser> countries) {
        this.countries = countries;
    }

    public List<OrganizationUser> getOrganizations() {
        return organizations;
    }

    public void setOrganizations(List<OrganizationUser> organizations) {
        this.organizations = organizations;
    }

    public List<LegalEntityUser> getEntities() {
        return entities;
    }

    public void setEntities(List<LegalEntityUser> entities) {
        this.entities = entities;
    }

    public List<OrganizationAssignableUser> getAssignableOrganizations() {
        return assignableOrganizations;
    }

    public void setAssignableOrganizations(List<OrganizationAssignableUser> assignableOrganizations) {
        this.assignableOrganizations = assignableOrganizations;
    }

    public Boolean getCanBeAssignedToCountry() {
        return canBeAssignedToCountry;
    }

    public void setCanBeAssignedToCountry(Boolean canBeAssignedToCountry) {
        this.canBeAssignedToCountry = canBeAssignedToCountry;
    }

    public Boolean getIsEmployee() {
        return isEmployee;
    }

    public void setIsEmployee(Boolean employee) {
        isEmployee = employee;
    }

    public Boolean getIsGlobalUser() {
        return isGlobalUser;
    }

    public void setIsGlobalUser(Boolean globalUser) {
        isGlobalUser = globalUser;
    }}

UserEdit Class

public class VTowerUserEditor extends UserEditor {
}

UserEdit XML

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        xmlns:ext="http://schemas.haulmont.com/cuba/window-ext.xsd"
        class="com.vtss.vtower.web.screens.user.VTowerUserEditor"
        extends="com/haulmont/cuba/gui/app/security/user/edit/user-edit.xml"
        messagesPack="com.vtss.vtower.web.screens.user">
    <layout/>
</window>

Code used to open User Edit Screen

 @Subscribe("legalEntityUsersTable.createLegalEntityUser")
    public void onLegalEntityUsersTableCreateLegalEntityUser(Action.ActionPerformedEvent event) {
        if (validateLegalEntityUserIsSelected()){
            User user = metadata.create(User.class);
            VTowerUserEditor userEditor = screenBuilders.screen(this)
                    .withScreenClass(VTowerUserEditor.class)
                    .withOptions(new MapScreenOptions(ParamsMap.
                            of(Constants.USER_PARAM, user, Constants.APPLICATION_ROLE_TYPE_PARAM, ApplicationRoleType.CLIENT,
                                    Constants.LEGAL_ENTITY_PARAM, legalEntitiesDc.getItem(),
                                    Constants.OPENED_FROM_PARAM, Constants.LEGAL_ENTITY_PARAM)))
                    .withLaunchMode(OpenMode.DIALOG).build();
            userEditor.addAfterCloseListener(listener -> {
                userService.initNewUser(user.getId(), legalEntitiesDc.getItem().getId());
                userService.createEmployeesGroupUser(legalEntitiesDc.getItem().getId(), user.getId());
            });
            userEditor.show();
            legalEntitiesDl.load();
        }
    }

Not Able to Open it showing that

VTowerUserEditor doesn’t have @UiController

so please let me know the best way to open User Editor Extended Screen

Hi,

A screen extending UserEditor is a legacy screen (we didn’t rewrite the platform screens to keep them compatible with existing extensions). So your new screen cannot be opened by class, but only by its id with which it is registered in web-screens.xml. For extended screens it’s always the same as the id of the base screen, in your case sec$User.edit.

Also, you should use proper methods of ScreenBuilders to open editor screen. So this code would work:

        screenBuilders.editor(MyUser.class, this)
                .withScreenId("sec$User.edit")
                .newEntity()
                .build()
                .show();

Moreover, as sec$User.edit id conforms to editor screen naming convention, you could omit the screen id, knowing the entity class is enough for the framework to find the editor:

        screenBuilders.editor(MyUser.class, this)
                .newEntity()
                .build()
                .show();

Regards,
Konstantin

Hi @knstvk,

Thanks it worked fine