Menu link to external URL in v7?

Hello:

I am trying to create an external link (google groups) directly from a menu item. This was asked and answered for v6, but the WindowManager is deprecated now. What is the correct way to implement this in v7?

https://www.cuba-platform.com/discuss/t/adding-menu-item-with-link-to-external-url/1569

Hi,

If you take a look into javadocs of the WindowManager#showWebPage method, you will see the suggestion to use another method:

    /**
     * Open a web page in browser.
     * <br>
     * It is recommended to use {@link WebBrowserTools} instead.
     *
     * @param url    URL of the page
     * @param params optional parameters.
     *               <br>The following parameters are recognized by Web client:
     *               <ul>
     *               <li>{@code target} - String value used as the target name in a
     *               window.open call in the client. This means that special values such as
     *               "_blank", "_self", "_top", "_parent" have special meaning. If not specified, "_blank" is used.</li>
     *               <li> {@code width} - Integer value specifying the width of the browser window in pixels</li>
     *               <li> {@code height} - Integer value specifying the height of the browser window in pixels</li>
     *               <li> {@code border} - String value specifying the border style of the window of the browser window.
     *               Possible values are "DEFAULT", "MINIMAL", "NONE".</li>
     *               </ul>
     *               Desktop client doesn't support any parameters and just ignores them.
     * @see WebBrowserTools#showWebPage(String, Map)
     */
    void showWebPage(String url, @Nullable Map<String, Object> params);
 * It is recommended to use {@link WebBrowserTools} instead.
 * @see WebBrowserTools#showWebPage(String, Map)

WebBrowserTools can be injected to any v7 screen.

When I try to execute the WebBrowserTools, I get this:
image

Screen is:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/screen/window.xsd"
        caption="msg://caption"
        messagesPack="com.paslists.merges.web.screens">
    <layout>
    </layout>
</window>

Controller is:

package com.paslists.merges.web.screens;

import com.google.common.collect.ImmutableMap;
import com.haulmont.cuba.gui.WebBrowserTools;
import com.haulmont.cuba.gui.screen.Screen;
import com.haulmont.cuba.gui.screen.Subscribe;
import com.haulmont.cuba.gui.screen.UiController;
import com.haulmont.cuba.gui.screen.UiDescriptor;

import javax.inject.Inject;

@UiController("merges_Googledatagroup")
@UiDescriptor("googleDataGroup.xml")
public class Googledatagroup extends Screen {

    @Inject
    private WebBrowserTools webBrowserTools;

    @Subscribe
    public void onInit(InitEvent event) {
        webBrowserTools.showWebPage("https://groups.google.com/a/paslists.com/forum/data", ImmutableMap.of("target","_top"));
    }  
}

I am running 7.1.3:
image

What did I do wrong?

So, I managed to get access to the WebBrowserTools object like this:

public class Googledatagroup extends Screen {

    private WebBrowserTools webBrowserTools;

    @Subscribe
    public void onInit(InitEvent event) {
        AppUI ui = AppBeans.get(AppUI.class);
        webBrowserTools = ui.getWebBrowserTools();

Unfortunately, it doesn’t seem to do anything. I get a blank page. When I watch the network interaction, I see this after clicking the Menu item. There is no data transfer from an external web page.
image

I tried switching the link to:

webBrowserTools.showWebPage("http://www.cuba-platform.com",null);

Still a blank page. Suggestions?

Hi,

The correct way to obtain WebBrowserTools is:

AppUI.getCurrent().getWebBrowserTools();

Adding menu item with a link to external URL requires creating a class that can be used as a menu item, e.g.:

public class ExternalUrlDemoRunner implements Runnable {
    @Override
    public void run() {
        AppUI.getCurrent().getWebBrowserTools()
                .showWebPage("http://www.cuba-platform.com", null);
    }
}

web-menu.xml

<menu-config xmlns="http://schemas.haulmont.com/cuba/menu.xsd">
    <menu id="application-demo" insertBefore="administration">
        ...
        <item id="external-link-demo"
              class="com.company.demo.web.menu.ExternalUrlDemoRunner"/>
    </menu>
</menu-config>

Regards,
Gleb