Hi guys,
application.getActiveWindow().controller.getName() returns a different name than currentcontroller.getName().
I assume this is not normal?
My function starts running in a window that opens another window, something like that:
function doWhatever() {
doSomethingInCurrentWindow();
openNewWindow();
forms[currentcontroller.getName()].doSomethingInNewWindow();
}
This works beautifully.
As soon as I replaced currentcontroller.getName() with application.getActiveWindow().controller.getName(), my last line is executed in the current window, not the new one.
Sample solution attached: click on the button to open a new window; upon opening a new window it will set the label text in the new window with the help of both currentcontroller and application.getActiveWindow(). The latter will set the label in the old window, the former - in the new.
This means those two are not interchangeable. We rely a lot on the currentcontroller in are existing solutions. Please advise how to deal with this and whether it’s a bug.
currentController.servoy (3.82 KB)
Hi Maria,
If you haven’t already I suggest you file this issue in the bug tracker. It sure looks like a bug to me.
Added my vote to the issue.
ROCLASI:
Added my vote to the issue.
Thanks Rob.
Did you have a look at Johan’s and my comments in the case? Are we missing each other’s point?
Hi Maria,
I added a comment to the issue.
It seems the order of events have changed when you create and open a new window and in that same method try to do things on the (new) active window.
At that point the new window is not active yet so getActiveWindow will return the old window (which is different behavior than when you used currentcontroller). So the trick is to call it after the method is done by putting the rest of your code in another method and deferring that method call by way of the scheduler plugin:
plugins.scheduler.addJob('DEFERRED', new Date(), myDeferredMethod);
This will trigger the method right after the current method is done.
Maybe I missed it but I can’t find no documentation of this behavior change in the release notes nor the wiki.
Hope this helps.
ROCLASI:
Hi Maria,
I added a comment to the issue.
It seems the order of events have changed when you create and open a new window and in that same method try to do things on the (new) active window.
At that point the new window is not active yet so getActiveWindow will return the old window (which is different behavior than when you used currentcontroller). So the trick is to call it after the method is done by putting the rest of your code in another method and deferring that method call by way of the scheduler plugin:
plugins.scheduler.addJob('DEFERRED', new Date(), myDeferredMethod);
This will trigger the method right after the current method is done.
Maybe I missed it but I can’t find no documentation of this behavior change in the release notes nor the wiki.
Hope this helps.
Thanks Robert.
I was trying to avoid using the schedulers, we’ve got a few in our app by now, but yes, it looks like there aren’t many options.