Setting user-specific default dashboard

Hi CUBA Team
In order to let the administrator select the user-specific dashboard in the main screen, I have extended the user Entity and added a field defaultDashboard which is basically an Association field of PersistentDashboard Entity. It works well if I hard-code the dashboard code in the xml file of mainScreen but how can I set the dashboard default to the respective users in the main screen (from Controller?)?

Something similar to this?

ExtPersistentDashboard dashboard =currentUser.getDefaultDashboard();
workArea.getInitialLayout().add(dashboard);

Hi ,

Through viewing the source code of "WebDashboardFrame ", i think that you can try this :

@Inject
protected DashboardFrame dashboardFrame;
void  public someMethod(){
    dashboardFrame.setCode(dashboardCodeForSpecificUser);
    dashboardFrame.refresh();
}

Thanks, Could you clarify what that “dashboardCodeForSpecificUser” represent? the Entity where the dashboard is saved is most likely in “ExtPersistentDashboard” and how can I set that to dashboardFrame.setCode() as it doesn’t seem to be the same! Thanks for explaining a bit more.

Hi ,

“dashboardCodeForSpecificUser” means a dashboard’s code value.
In your case “dashboardCodeForSpecificUser” should be get using following code:

ExtPersistentDashboard dashboard =currentUser.getDefaultDashboard();
String dashboardCode=  dashboard.getCode();

Tried it as suggested

@Inject
protected DashboardFrame dashboardSales;

 ExtPersistentDashboard dashboard =currentUser.getDefaultDashboard();
                String dashboardCode=  dashboard.getCode();
                dashboardSales.setCode(dashboardCode);
                dashboardSales.refresh();

but getting the following exception:

    09:11:26.339 WARN  c.h.c.g.s.UiControllerDependencyInjector- Unable to find an instance of type 'interface com.haulmont.addon.dashboard.gui.components.DashboardFrame' named 'dashboardSales' for instance of 'com.company.web.mainwindow.ExtAppMainWindow'
09:11:26.366 WARN  c.h.c.w.a.loginwindow.AppLoginWindow    - Unable to login
java.lang.NullPointerException: null
	at com.company.web.mainwindow.ExtAppMainWindow.getUserType(ExtAppMainWindow.java:306) ~[myApp-web-2019.06.17-SNAPSHOT.jar:na]

Hi @mortozakhan

Seems that threre is no a DashboardFrame named ‘dashboardSales’ in the ExtAppMainWindow , but i’m not sure ,because not have enought information .

Hi @mortozakhan ,

Here is some code fragment ,hope it is useful to you.

image
image

Thank you so much Ray.