Migrate 5.3 to 7.0 - XmlHttpRequest issue

UI Components for JSF
Post Reply
Nicolas D
Posts: 5
Joined: 07 Jun 2019, 10:50

12 Jun 2019, 09:05

Hello everyone,

I must to migrate PF 5.3 to 7.0 and i have an issue with a XmlHttpRequest.
In 5.2 and 6.1 xhr of callPrint function return the correct XML response but since 6.2 it return only the PDF file with parse error.
This code is used to generate and download a PDF file.

Has anyone ever had this issue ?

Code: Select all

<p:commandButton id="impression"  action="#{beanPrint.imprimer(false)}"
                 oncomplete="callPrint(xhr, status, args);"/>

Code: Select all

function callPrint(xhr, status, args) {

    if (xhr.getResponseHeader("Content-Disposition") == null) {
        return;
    }
    var contentDisposition = xhr.getResponseHeader("Content-Disposition").split(";");
    var filename = "";
    var type = "";
    var option = "";
    var i = 0;
    while (i < contentDisposition.length) {
        if (contentDisposition[i].indexOf("filename=") > -1) {
            filename = contentDisposition[i].replace("filename=", "");
        } else if (contentDisposition[i].indexOf("type=") > -1) {
            type = contentDisposition[i].replace("type=", "");
        } else if (contentDisposition[i].indexOf("option=") > -1) {
            option = contentDisposition[i].replace("option=", "");
        }
        i++;
    }
...
}

Code: Select all

public void imprimer(boolean apercu) {

	InputStream inputStream;

	... Code to generate InputStream from PDF File ...

	printService.directPrint(inputStream, "pdf", "");

}

Code: Select all

public void directPrint(InputStream inputStream, String typeFichier, String option) throws IOException {
	       
        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
        response.setCharacterEncoding("ISO-8859-1");
       
	response.setContentType("application/pdf");
	response.addHeader("Content-disposition", "inline;filename=directPrint.pdf" + (typeFichier != null ? (";type=" + typeFichier + ";option=" + option) : "") + ";");
              
        response.setHeader("Cache-Control", "");
        response.setHeader("Pragma", "");

        DataOutputStream os = new DataOutputStream(response.getOutputStream());
        byte[] buffer = new byte[1024];
        int len = 0;
        while ((len = inputStream.read(buffer)) >= 0) {
            os.write(buffer, 0, len);
        }
        response.getOutputStream().flush();
        response.getOutputStream().close();
        context.responseComplete();

        inputStream.close();
}
Thanks for helping !
Primefaces 7.0 - JSF 2.1.27

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

12 Jun 2019, 13:03

Did you just upgrade your PF version or did you also change your JSF version or server or any other pieces?

Here is possible change that could have affected the XHR: https://github.com/primefaces/primefaces/issues/3117
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Nicolas D
Posts: 5
Joined: 07 Jun 2019, 10:50

12 Jun 2019, 13:54

Tanks for answer,

Only PF dependency is upgrade to 7.0, do I need to update jsf too ?
Primefaces 7.0 - JSF 2.1.27

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

12 Jun 2019, 14:34

No I was just asking. the jump from 5.3 to 7.0 includes so many fixes and Jquery from 1.8 to 3.3 that its possible anything could be causing the issue. You will have to debug and dig deeper.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Nicolas D
Posts: 5
Joined: 07 Jun 2019, 10:50

12 Jun 2019, 15:59

After a long time to debug i found this in META-INF\resources\primefaces\core.js

Image

When i replace B by A it works well, but I don't know if it's a good correction.
Primefaces 7.0 - JSF 2.1.27

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

12 Jun 2019, 16:05

PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Nicolas D
Posts: 5
Joined: 07 Jun 2019, 10:50

12 Jun 2019, 16:17

I haven't this folder in PF 7.0 JAR. The file is here META-INF\resources\primefaces\core.js

Sorry for ask but i don't understand what is wrong and what i need to do.

Change core.js of my jar and replace B by A or it's a real bug and it will be corrected in the next update ?
Primefaces 7.0 - JSF 2.1.27

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

12 Jun 2019, 16:48

No your code is the compressed and minified JS. What I sent you was the raw source code of what you are reporting as "A and B" are actually real variables.

I will defer to @tandraschko on whether it is a bug. You should report it with all the details and a reproducible test case to the Issues Page.

Using Primefaces Test please create a reproducible test case: https://github.com/primefaces/primefaces-test
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Nicolas D
Posts: 5
Joined: 07 Jun 2019, 10:50

14 Jun 2019, 10:37

Hello,

Tanks for answer, ticket was open here : https://github.com/primefaces/primefaces/issues/4898
Primefaces 7.0 - JSF 2.1.27

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

18 Jun 2019, 17:20


Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 29 guests