微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在Vaadin14中打开外部BIRT链接时遇到问题

如何解决在Vaadin14中打开外部BIRT链接时遇到问题

我正在尝试从下面的屏幕中输入内容,然后将Birt Report直接打开为PDF。 (我正在使用Vaadin 14)

问题: 每次加载此UI时,我的锚定/按钮在第一次单击时都未打开任何链接。但是从第二次单击开始单击一次后,它可以正常工作。知道是什么问题,我犯了什么错误

enter image description here

以下是我的全局变量

final Button                    printButton                     =
    new Button("Print Report",VaadinIcon.PRINT.create());
String                          url                             = null;
final Anchor                    anchorReport                    = new Anchor();

我的咨询师:

public AssignmentCompletedAllRPTView()
{
    super();
    this.initUI();
    this.radioButtonGroup.setItems("Yes","No");
    this.printButton.addClickListener(new ComponentEventListener<ClickEvent<Button>>()
    {
        @Override
        public void onComponentEvent(final ClickEvent<Button> event)
        {
            AssignmentCompletedAllRPTView.this.printButton();
        }
    });
    this.ConfigureReportButton();
}

ConfigureReportButton():

private void ConfigureReportButton()
{
    this.anchorReport.setTarget("_blank");
    this.anchorReport.add(this.printButton);
    this.buttonHorizontalLayout.add(this.anchorReport);
}

printButton():

private void printButton()
{
        final String reportURL = //--URL
        this.anchorReport.setHref(reportURL);
}

解决方法

通过不使用Anchor来解决,但是通过使用executeJavaScript来解决(尽管它已被描述但运行良好):

UI.getCurrent().getPage().executeJavaScript("window.open(\"" + reportURL + "\",\"_blank\");");
,

您在此处有两个组件:ButtonAnchor。您的Button放在Anchor中的ConfigureReportButton内部。您的Button还会在构造函数中获得一个点击侦听器。

当您第一次单击锚点内的按钮时,锚点没有href,因此它什么也不做。它还执行方法printButton,该方法更新锚点的href。下次单击锚点内的按钮时,锚点设置为href,因此将加载文件。它还会再次执行按钮的点击侦听器,因此href得到更新。

要解决此问题,请在构造函数的末尾执行printButton()

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。