mario
(Mario David)
November 24, 2016, 9:42am
#1
Hi,
i encountered a little problem with the active tab when a screen is opened programatically. Here’s the example:
Mainwindow onReady: openWindow(‘customer.browse’) --> opens the customer browse in tab 1
User clicks in main menu on customers --> opens the customer browse in tab 2
User clicks in main menu on customer once again --> re-opens the customer browse in tab 2
Expected behavior:
Mainwindow onReady: openWindow(‘customer.browse’) --> opens the customer browse in tab 1
User clicks in main menu on customers --> opens the customer browse in tab 1
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
artamonov
(Yuriy Artamonov)
November 28, 2016, 3:05pm
#2
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.
mario
(Mario David)
December 2, 2016, 7:21pm
#3
Hi Yuiry,
thanks for the explanation. I’m looking forward to the improvement.
Bye,
Mario
artamonov
(Yuriy Artamonov)
December 3, 2016, 11:32am
#4
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
mario
(Mario David)
December 3, 2016, 6:59pm
#5
hi,
thanks, i’ll give it a try!
Bye
Mario
Thanks for the workaround. Works great.
system
(system)
September 15, 2017, 5:37am
#7
zoell3248
(Zoltan Szabo)
January 15, 2019, 5:07pm
#8
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.
artamonov
(Yuriy Artamonov)
January 17, 2019, 7:12am
#9
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);
}
}