Adding a generic edit view for the userSession

We created our Customers by extending your Users. Then, we have created our own generic view from Customer Browse so that it can display all the details about a given Customer. For this functionality, we have overridden the controller by extending the AbstractLookup.
Controller


package com.company.demo.web.customer;

import com.haulmont.cuba.gui.components.AbstractLookup;
import com.haulmont.cuba.gui.components.actions.EditAction;

import javax.inject.Named;
import java.util.Map;

public class CustomerBrowse extends AbstractLookup {
    @Named("customersTable.edit")
    private EditAction customerDetailsView;

    @Override
    public void init(Map<String, Object> params) {
    customerDetailsView.setWindowId("demo$Customer.edit");
    }
}

We have also modified our main screen so that now it displays the userSession right after the log in, by overriding the controller for the usersession.
controller


package com.company.demo.web.usersession;

import com.haulmont.cuba.gui.app.security.session.browse.SessionBrowser;
import com.haulmont.cuba.gui.components.Component;
import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.gui.components.TextField;
import org.apache.commons.lang.StringUtils;

import javax.inject.Inject;
import java.util.HashMap;
import java.util.Map;

public class ExtSessionBrowser extends SessionBrowser {
    
    public ExtSessionBrowser() {
        super();
    }

    @Override
    public void init(Map<String, Object> params) {
        super.init(params);
    }

    @Override
    public void refresh() {
        super.refresh();
        Map<String, Object> fieldValues = new HashMap<>();
        String userLoginStr = userLogin.getValue();
        if (!StringUtils.isEmpty(userLoginStr))
            fieldValues.put("userLogin", userLoginStr.toLowerCase());
        String userNameStr = userName.getValue();
        if (!StringUtils.isEmpty(userNameStr))
            fieldValues.put("userName", userNameStr.toLowerCase());
        String userAddressStr = userAddress.getValue();
        if (!StringUtils.isEmpty(userAddressStr))
            fieldValues.put("userAddress", userAddressStr.toLowerCase());
        String userInfoStr = userInfo.getValue();
        if (!StringUtils.isEmpty(userInfoStr))
            fieldValues.put("userInfo", userInfoStr.toLowerCase());
        sessionsDs.refresh(fieldValues);
    }

    @Override
    public void clearTextFields() {
        super.clearTextFields();
    }

    @Override
    public void message() {
        super.message();
    }

    @Override
    public void kill() {
        super.kill();
    }
}

We would now want to replicate the Customer Details view but only for the userSession not for all the Customers.
How can we do that since the controller for the usersession browser view already extends SessionBrowser and cannot extend AbstractLookup at the same time? Thank you.

SessionBrowser extends AbstractLookup, so your ExtSessionBrowser already extends it too.
However, I don’t quite understand what you are going to achieve, so if you have further questions, please attach a demo project.

1 Like

Thank you Konstantin. This helps.

How can I create an editView for the usersession to include information from our entities? You only have a SessionBrowser. How can we make a SessionEdit? Thank you.

UserSessionEntity is not a persistent entity, it is loaded by UserSessionsDatasource from UserSessionService. So you should create a screen with the controller inherited from AbstractWindow and open it with the openWindow() method. Pass the session entity to display in the map of parameters.

We are now able to display the same window we have for Customers(Users) when we double click on a particular usersession. However, that window can fill in correctly only the login filed but none of the other info that we know about that user because it’s stored in the database. We accomplished this by adding customerDetailsView.setWindowId(“demo$Customer.edit”); to the init method of the controller for the ExtSessionBrowser

so part of the ExtSessionBrowser looks like this:

@Named("sessionsTable.edit")
private EditAction customerDetailsView;

@Override
public void init(Map<String, Object> params) {
    customerDetailsView.setWindowId("demo$Customer.edit");
}

Our “demo$Customer.edit” window displays all the info we have in the database about a given user.
What should we use in the controller for the ExtSessionBrowser to enable to display all the data we have in the database for a particular user who is also a usersession? Something that would allow us to select a user info based on the sessionuser login?

Thank you.

If you want to display additional columns with User attributes in your ExtSessionBrowser screen, you can use the following approach:

  • Create a new non-persistent entity inherited from UserSessionEntity. You cannot select a non-persistent base class in Studio now, so switch to the IDE and replace the base class with UserSessionEntity. Add user association attribute of User type.

  • Create a new custom datasource for loading your new entities. Copy the implementation of UserSessionsDatasource and add loading of users for each session.

  • In your extended session browse screen, use your new datasource and add columns to the table to display related user attributes.