Adding menu item with link to external url?

How do I add a menu item that links to an external url and another menu item that link to an url in the app domain?

Thanks…

Hi,

Currently, it can be done only from IDE:

  1. Create Java class that implements Runnable and uses WindowManager to show an external web page:

public class ExternalUrlDemoRunner implements Runnable {
    @Override
    public void run() {
        App app = App.getInstance();
        WebWindowManager wm = app.getWindowManager();
        wm.showWebPage("http://google.com", null);
    }
}
  1. Add to your web-screens.xml new screen item where set class to full name of your Runnable class:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<screen-config xmlns="http://schemas.haulmont.com/cuba/screens.xsd">
    <include file="com/company/demo/screens.xml"></include>

    <screen id="external-demo" class="com.company.demo.web.ExternalUrlDemoRunner"></screen>
</screen-config>
  1. Call Open web menu action from Generic UI tab in Studio and add new menu item with screen id external-demo. Click OK to save menu definition.

Now you can click on your new menu item and it will open additional browser tab with an external URL. Please note that users have to allow pop-up windows on your application domain otherwise they will see a warning in a web browser.

If you want to open some page on application domain you can obtain the application URL using ControllerUtils:


import com.haulmont.cuba.web.controllers.ControllerUtils;
...
String currentAppUrl = ControllerUtils.getLocationWithoutParams();

See also: A.screens.xml - CUBA Platform. Developer’s Manual

1 Like

WOW…Thank you for your help…

CUBA…This is particularly painfully and complex to do such a simple task. Is there no way for the CUBA platform to accomplish this easier???

CUBA was designed to save time in development, but this oversight has given me second thoughts is using this platform to port my application to.

Disappointed !!!

1 Like

Just a follow up…

I needed a sub-menu of the “Help” menu to actually point to my app helper section (url). How do I do this a a sub-menu item… (Help -> my-url) ? Doe working with the “Help” menu change the way this modification is done?

Thanks

Hi Donavon,

You are right, the API is currently not very nice. We will consider changing it to make such custom operations for the menu actions more friendly.

Regards,

Aleksey

Hi, sorry for the late answer.

You can do this using Studio Menu Designer. Set Insert before parameter for your menu items or sub menus to aboutWindow.

menu-insert-before

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

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

Hi Aleksey,
Are there any news on this?
Adding menu item which link to external url is so complicated.