1

All,

I'm working in JSF / Jave / Primefaces.

When the user clicks a command button, I'd like to grab the box number and open up two different URLs at once, which would give the end user two different files to download.

I've tried quite a few suggestions and, so far, I've been unsuccessful. I'd prefer to not use JS if possible, but am open to suggestions.

I tried to just repeat the URL build and call again, but that did not work.

Thanks for any suggestions!

Christina

JSF:

<p:commandButton value="Open / Print Documentation" icon="fa fa-folder-open"
                                                     id="ajax" style="height:40px;" update="growl"
                                                     rendered='#{userManager.hasRole("RecordsManagementEndUsers")}'
                                                     actionListener="#{dashboardView.openPdf}">
                                    </p:commandButton>

Java:

    public void openPdf(ActionEvent actionEvent) {
    String response = confirmBoxId(boxNumber);

    if (response == "in system") {

        ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();

        String url =
            "http://linkGoesHere.xdo?_xpt=1&_xf=pdf&rec_num=" +
            boxNumber + "&_xt=CM_RECTRANS";
        try {
            FacesContext.getCurrentInstance()
                        .getExternalContext()
                        .redirect(url);
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        addMessageWarn("Box number " + boxNumber + " was not found in the system. Please try again.");
    }
}

The second URL would be something like this:

"http://linkGoesHere.xdo?_xpt=1&_xf=pdf&rec_num=" + boxNumber + "&_xt=labels";
Christina
  • 31
  • 5

1 Answers1

0

I have gotten this to work so far, with quirks on the other side that I'll have to work through (mentioned below).

I went ahead and used the onclick to open the two URLs:

<p:commandButton value="Open / Print Documentation" icon="fa fa-folder-open"
     id="ajax" style="height:40px;" update="growl"
     rendered='#{userManager.hasRole("RecordsManagementEndUsers")}'
     onclick = "window.open('http://linkGoesHere.xdo?_xpt=1&amp;_xf=pdf&amp;rec_num=' + #{dashboardView.boxNumber} + '&amp;_xt=labels');
     window.open('http://linkGoesHere.xdo?_xpt=1&amp;_xf=pdf&amp;rec_num=' + #{dashboardView.boxNumber} + '&amp;_xt=CM_RECTRANS');">

It opens the two links successfully but now I need to determine a way to validate when the box number cannot be found, which I was previously doing on the Java side.

So, it may not be a permanent solution in my case, but it's a working one, assuming the passed values will always generate working links.

Christina
  • 31
  • 5
  • The onclick attribute does actually call a js function upon the event fires (which in this case, is the click). To determine the correct 'boxNumber', you might just continue to use the actionListener implemented earlier (but remove the redirect part ofc) to evaluate the number and switch from using the 'onclick' attribute to the 'oncomplete' which will assure you the js will be called after the model has been updated. – Endrik Mar 28 '18 at 22:12