简体   繁体   中英

Flying Saucer prints EL expression instead of real values in generated PDF

I'm trying to generate PDF from xhtml page using Flying Saucer. My related codes are below.

pdf.xhtml works fine itself.

However generated pdf contains EL expression #{basvuruBean.sirketAdi} instead of entered value of sirketadi property of backing bean if i try to create pdf from using CreatePDF backing bean method. Backing bean is sessionscoped.

What is wrong with my codes?

Thanks for in advance.

Another library recommendation for generating pdf from jsf page with backing bean?

The xhtml page which is base for generated pdf: pdf.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:ui="http://java.sun.com/jsf/facelets">

<h:head>
</h:head>
        <body>Sirket Adı: #{basvuruBean.sirketAdi}
</body>
</html>

Create PDF method in basvuruBean backing bean

public void createPDF() {


            FacesContext facesContext = FacesContext.getCurrentInstance();
            ExternalContext externalContext = facesContext.getExternalContext();
            String servername = externalContext.getRequestServerName();
            String port = String.valueOf(externalContext.getRequestServerPort());
            String appname = externalContext.getRequestContextPath();
            String protocol = externalContext.getRequestScheme();
            HttpSession session = (HttpSession) externalContext.getSession(true);
            this.url = protocol + "://" + servername + ":" + port + appname + "/"+PDF_PAGE+";JSESSIONID=" + session.getId();
            try {
                ITextRenderer renderer = new ITextRenderer();
                renderer.setDocument(new URL(this.url).toString());
                renderer.layout();
                HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
                response.reset();
                response.setContentType("application/pdf");
                response.setHeader("Content-Disposition", "inline; filename=\"" + PDF_FILE_NAME + "\"");
                OutputStream browserStream = response.getOutputStream();
                renderer.createPDF(browserStream);

            } catch (Exception ex) {
                Logger.getLogger(BasvuruBean.class.getName()).log(Level.SEVERE, null, ex);
            }
            facesContext.responseComplete();

That can happen if the request URL did not match the URL pattern of the FacesServlet . It's the one responsible for performing all the JSF/EL works. So, if you've mapped the Faces Servlet on an URL pattern of for example *.jsf , then you should point to pdf.jsf , not pdf.xhtml .


Unrelated to the concrete problem, the jsessionid path fragment must be in all lowercase.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM