Java iText Pdf Writer and PrimeFaces Not Refreshin

2019-09-09 17:28发布

Good morning! I'm using the iText library to create a pdf template and Primefaces to display the content on a web application. When I ran the first test to see if all the libraries were all set, it was displayed normally. But then I made some changes, and it seems that something is caching my first test in memory and it is the only thing displayed, no matter what changes I make it keeps the same first content. I´ve already cleaned up my netbeans project, closed the IDE and also restarted the computer.

Thats is my tag on the jsf page:

<p:media value="#{atividadeController.pdfContent}" player="pdf" width="100%" height="700px"/>

And here is my method in the managed bean, which is a SessionScoped:

public String preparePdf()
{
try {             
    ByteArrayOutputStream output = new ByteArrayOutputStream();  

    Font fontHeader = new Font(Font.FontFamily.HELVETICA, 20, Font.BOLD);
    Font fontLine = new Font(Font.FontFamily.TIMES_ROMAN, 14);
    Font fontLineBold = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD);

    Document document = new Document();
    PdfWriter.getInstance(document, output);  
    document.open(); 

    //Writing document
    Chunk preface = new Chunk("GERAL", fontHeader);
    document.add(preface);  

    Calendar cal = Calendar.getInstance();
    cal.setTime(current.getData());
    int year = cal.get(Calendar.YEAR);
    int month = 1 + cal.get(Calendar.MONTH);
    int day = cal.get(Calendar.DAY_OF_MONTH);
    String dateStr = day+"/"+month+"/"+year;
    Paragraph dataAndHour = new Paragraph(dateStr, fontLine);
    document.add(dataAndHour);

    document.close();  
    pdfContent = new DefaultStreamedContent(new          ByteArrayInputStream(output.toByteArray()), "application/pdf");  

} catch (Exception e) {  
    e.printStackTrace();  
}  

  return "/views/view_atividade_pdf";
}

There is no exception on the server log. I really aprecciate any help. Thanks in advance

0条回答
登录 后发表回答