当我点击按钮时没有任何反应。在JSF按钮上点击执行java方法点击
<h:commandButton value="Generate PDF" type="button"
action="#{parseHtml12.createPdf}" />
此按钮位于XHTML文件中,我要将其转换为pdf。 Java类代码是在这里:
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();
}
}
此代码是不错,唯一的问题是如何在按钮点击执行类。 当我在IDE中运行类给我的结果,但问题是,XHTML中的内容是动态的,不检索值。
如果我执行类时,值将被填充,这会给我想要的结果。
更新:点击按钮时,动态数据消失。如果我再次点击发生像这样: javax.el.PropertyNotFoundException: /data.xhtml @48,45 action="#{parseHtml12.createPdf}": Target Unreachable, identifier 'parseHtml12' resolved to null
这似乎不是一个iText问题。在编写自己的代码时,使用Java编写的iText代码部分可以正常运行,因此您的问题在JSF中是孤立的。我建议你删除iText标签。 –