【问题标题】:Having an issue while opening external BIRT link in Vaadin14在 Vaadin 14 中打开外部 BIRT 链接时出现问题
【发布时间】:2021-02-17 04:47:58
【问题描述】:

我正在尝试从下面的屏幕中获取输入并将 Birt Report 直接打开为 PDF。 (我正在使用 Vaadin 14)

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

以下是我的全局变量:

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);
}

【问题讨论】:

  • 您能否最小化您的代码示例以仅包含重现问题所需的行?现在有大量的代码我认为与手头的问题无关,就像所有的日志记录一样。
  • 我实际上不知道在第一次点击时出现问题的地方。我很抱歉,但会缩短 printButton() 方法。删除所有日志。我做到了。
  • 重现问题是否需要这些通知?
  • 我删除了所有不必要的代码。我希望有人能回复我,我在编码中做错了什么而不是在发布中:( .
  • 我也注意到:它总是取之前的值。例如,在初始点击中,它不设置任何内容,然后更改它选择以前的值而不是当前值的日期。

标签: vaadin vaadin-flow rapidclipse


【解决方案1】:

这里有两个组件:ButtonAnchor。您的Button 被放置在AnchorConfigureReportButton 中。你的Button 还在构造函数中获得了一个点击监听器。

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

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

【讨论】:

    【解决方案2】:

    通过不使用 Anchor 而是使用 executeJavaScript 解决(虽然它被贬低但工作正常):

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-19
      相关资源
      最近更新 更多