在Vaadin14中打开外部BIRT链接时出现问题 我正试图从下面的屏幕获取输入,并将Birt报告直接打开为PDF格式。(我正在使用Vaadin 14)

在Vaadin14中打开外部BIRT链接时出现问题 我正试图从下面的屏幕获取输入,并将Birt报告直接打开为PDF格式。(我正在使用Vaadin 14),vaadin,vaadin-flow,rapidclipse,Vaadin,Vaadin Flow,Rapidclipse,问题: 每次加载此UI时,我的锚/按钮不会在第一次单击时打开任何链接。但从第二次单击开始单击一次后,它工作正常。你知道会是什么问题吗?我犯了什么错误 下面是我的全局变量: final Button printButton = new Button("Print Report", VaadinIcon.PRINT.create()); String

问题: 每次加载此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();
}
private void ConfigureReportButton()
{
    this.anchorReport.setTarget("_blank");
    this.anchorReport.add(this.printButton);
    this.buttonHorizontalLayout.add(this.anchorReport);
}
private void printButton()
{
        final String reportURL = //--URL
        this.anchorReport.setHref(reportURL);
}
我的消费者:

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();
}
private void ConfigureReportButton()
{
    this.anchorReport.setTarget("_blank");
    this.anchorReport.add(this.printButton);
    this.buttonHorizontalLayout.add(this.anchorReport);
}
private void printButton()
{
        final String reportURL = //--URL
        this.anchorReport.setHref(reportURL);
}
printButton():

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();
}
private void ConfigureReportButton()
{
    this.anchorReport.setTarget("_blank");
    this.anchorReport.add(this.printButton);
    this.buttonHorizontalLayout.add(this.anchorReport);
}
private void printButton()
{
        final String reportURL = //--URL
        this.anchorReport.setHref(reportURL);
}

通过不使用锚点而是使用executeJavaScript解决(尽管它经过了打磨,但工作正常):


这里有两个组件:一个
按钮
和一个
锚定
。您的
按钮
位于
配置报告按钮
中的
锚定
内。您的
按钮
也会在构造函数中获得一个单击侦听器

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


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

能否将代码示例最小化,使其仅包含重现此问题所需的行?现在,我假设有大量代码与手头的问题无关,就像所有的日志记录一样。我不知道第一次单击时它在哪里有问题。很抱歉,我将短接printButton()方法。删除所有日志。我做到了。重现问题需要这些通知吗?我删除了所有不必要的代码。我希望有人会回复我,我在编码和发布方面做错了什么:(。我也注意到:它总是采用以前的值。例如,在最初的单击中,它没有设置任何内容,然后更改它选择以前值而不是当前值的日期。