Opening screen programatically differs from manual opening in Tab behavior

Hi,

i encountered a little problem with the active tab when a screen is opened programatically. Here’s the example:

  1. Mainwindow onReady: openWindow(‘customer.browse’) --> opens the customer browse in tab 1
  2. User clicks in main menu on customers --> opens the customer browse in tab 2
  3. User clicks in main menu on customer once again --> re-opens the customer browse in tab 2

Expected behavior:

  1. Mainwindow onReady: openWindow(‘customer.browse’) --> opens the customer browse in tab 1
  2. User clicks in main menu on customers --> opens the customer browse in tab 1
  3. User clicks in main menu on customer once again --> re-opens the customer browse in tab 1

Attached you’ll find the example project…

Bye,
Mario

cuba-problem-open-screen-prog-twice.zip (31.1K)

1 Like

Hi,

this difference is result of com.haulmont.cuba.gui.config.MenuCommand#loadParams that passes additional parameters to a window if it is opened from AppMenu. Two windows are considered different if their parameters are different.

We will try to improve this mechanism, but I cannot certainly say when it will be changed.

Hi Yuiry,

thanks for the explanation. I’m looking forward to the improvement.

Bye,
Mario

I’ve found simple workaround which can be useful for you now. You can pass the same parameters as menu passes to your screen when you open it programmatically (by default it is only “CAPTION”):


String windowId = "ref$Colour.browse";
Map<String, Object> params = ParamsMap.of(WindowParams.CAPTION.name(), 
        MenuConfig.getMenuItemCaption(windowId));
openWindow(windowId, OpenType.NEW_TAB, params);
1 Like

hi,

thanks, i’ll give it a try!

Bye
Mario

Thanks for the workaround. Works great.

:ticket: See the following issue in our bug tracker:

https://youtrack.cuba-platform.com/issue/PL-8278

The getMenuItemCaption is deprecated and I don’t have the getItemCaption which is in the documentation but it is not in my 6.10.2 version.

In fact, getItemCaption is instance method. So you can replace deprecated method usage as follows:

public class Screen extends AbstractWindow {
    @Inject
    private MenuConfig menuConfig;  // inject bean

    public void click() {
        String windowId = "ref$Colour.browse";
        Map<String, Object> params = ParamsMap.of(WindowParams.CAPTION.name(),
                menuConfig.getItemCaption(windowId));
        openWindow(windowId, WindowManager.OpenType.NEW_TAB, params);
    }
}