Having an issue while opening external BIRT link in Vaadin14

129 views Asked by At

I am trying to take input from the below screen and open Birt Report directly into PDF. (I am using Vaadin 14)

Problem: My Anchor/Button is not opening any link on the first click every time this UI gets loaded. But After clicking once from the second click onward, it is working fine. Any Idea what can be the issue and what mistake I've made?

enter image description here

Below are my global Variables:

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

My Consutructor:

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

There are 2 answers

0
Prashant Kumar On

Solved by not using Anchor but by using executeJavaScript (although it is depricated but working fine):

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

You have two components here: a Button and an Anchor. Your Button is placed inside the Anchor in ConfigureReportButton. Your Button also gets a click listener in the constructor.

When you first click the button inside the anchor, the anchor has no href, so it does nothing. It also it executes the method printButton, which updates the href of the anchor. When you next click the button inside the anchor, the anchor has a href set, so it loads the file. It also executes the click listener of the button again, so the href gets updated.

To fix the issue, execute printButton() at the end of the constructor.