0

When I click on button nothing happens.

 <h:commandButton value="Generate PDF" type="button"
        action="#{parseHtml12.createPdf}" />

This button is in XHTML file which I want convert to pdf. Java class code is here :

public class ParseHtml12 {
    public static final String DEST = "C:\\Users\\User\\Desktop/report.pdf";
    public static final String HTML = "web/data.xhtml";

    public static void main(String[] args) throws IOException, DocumentException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new ParseHtml12().createPdf(DEST);
    }


    public void createPdf(String file) throws IOException, DocumentException {

        Document document = new Document();

        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        writer.setInitialLeading(12);

        document.open();

        XMLWorkerHelper.getInstance().parseXHtml(writer, document,
                new FileInputStream(HTML));

        document.close();
    }
}

This code is good , only problem is how execute class on button click. When I run class in IDE gives me the result but the problem is that the content in XHTML is dynamic and does not retrieve values.

If I execute class when the value will be filled , this will give me desired result.

UPDATE: When the button is clicked dynamic data disappear. And if I click once again happens like this: javax.el.PropertyNotFoundException: /data.xhtml @48,45 action="#{parseHtml12.createPdf}": Target Unreachable, identifier 'parseHtml12' resolved to null

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
digo
  • 25
  • 7
  • This doesn't seem to be an iText question. As you write yourself, the iText part of code, in Java, is ok when you run it in your IDE, so your problem is isolated in your JSF. I suggest that you remove the iText tag. – Amedee Van Gasse Aug 30 '16 at 20:33

1 Answers1

2

I don't have enough points to comment.

try wrapping your commandButton inside a <h:form> tag, and add type="submit" to the button.

Sam
  • 605
  • 9
  • 19
  • Thanks. It helped me start button but when the button is clicked dynamic data disappear. And if I click once again happens like this: `javax.el.PropertyNotFoundException: /data.xhtml @48,45 action="#{parseHtml12.createPdf}": Target Unreachable, identifier 'parseHtml12' resolved to null` – digo Aug 30 '16 at 20:17
  • `createPdf`, is a method not an attribute, plus it has a String parameter, it should be `#{parseHtml12.createPdf(the name of your file)}` – Sam Aug 30 '16 at 20:24
  • unrelated, try to handle the 2 exceptions in the `createPdf` method, just throwing them is not practical. try `FacesMessage` with `` – Sam Aug 30 '16 at 20:27
  • I tried different combinations `#{parseHtml12.createPdf(the name of your file)}` but still the same error – digo Aug 31 '16 at 09:54
  • Thanks had the same issue and your answer solved my problem! – Fotis Sep 29 '20 at 09:40