p:dataExporter不能识别p:cellEditor [英] p:dataExporter does not recognize p:cellEditor

查看:220
本文介绍了p:dataExporter不能识别p:cellEditor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可编辑的< p:dataTable> < p:cellEditor> 使用< p:dataExporter> 将该表的内容导出为PDF格式。

I have an editable <p:dataTable> with <p:cellEditor> and I want to export the content of that table into PDF format using <p:dataExporter>.

strong> itext 2.1.7 jar 。我得到了PDF的输出,但它显示所有< p:cellEditor> Object#toString()组件如下所示:

I have included the itext 2.1.7 jar. I got the output in PDF but it shows the Object#toString() values of all <p:cellEditor> components like so:

org.primefaces.component.celleditor.CellEditor@1bd59e1

如何导出< p:cellEditor> 的输出值? p>

How do I export the output values of the <p:cellEditor> instead?

推荐答案

< p:cellEditor> 确实不被PrimeFaces认可标准数据出口商。
我以前向PF家伙报告了这一点:问题4013 与一个例子,它不仅提到 CellEditor ,而且 HtmlGraphicImage (我们正在使用图像显示布尔状态,其 alt 我们想在PDF / XML / XLS / CSV报告中显示)。

The <p:cellEditor> is indeed not recognized by the PrimeFaces standard data exporters. I've previously reported this to the PF guys as issue 4013 with an example which not only mentions CellEditor, but also HtmlGraphicImage (we are using images to show boolean states, whose alt we'd like to show in PDF/XML/XLS/CSV reports).

首先,创建一个新类它扩展了标准的 PDFExporter ,如下所示:

First, create a new class which extends the standard PDFExporter like follows:

public class ExtendedPDFExporter extends PDFExporter {

    @Override
    protected String exportValue(FacesContext context, UIComponent component) {
        if (component instanceof CellEditor) {
            return exportValue(context, ((CellEditor) component).getFacet("output"));
        }
        else if (component instanceof HtmlGraphicImage) {
            return (String) component.getAttributes().get("alt");
        }
        else {
            return super.exportValue(context, component);
        }
    }

}

然后,使用它,以编程方式调用,而不是通过< p:dataExporter>

Then, to use it, call it programmatically instead of via <p:dataExporter>.

<p:dataTable binding="#{table}" editable="true" ...>
    <p:column><p:cellEditor>...</p:cellEditor></p:column>
    <p:column><p:cellEditor>...</p:cellEditor></p:column>
    <p:column><p:cellEditor>...</p:cellEditor></p:column>
    <p:column exportable="false"><p:rowEditor /></p:column>
</p:dataTable>
<h:commandLink value="PDF" action="#{bean.exportPDF(table, 'filename')}" />

public void exportPDF(DataTable table, String filename) throws IOException {
    FacesContext context = FacesContext.getCurrentInstance();
    Exporter exporter = new ExtendedPDFExporter();
    exporter.export(context, table, filename, false, false, "UTF-8", null, null);
    context.responseComplete();
}

随意查找 UIComponent# findComponent()而是仅在action方法中设置文件名。以上代码只是示范。

Feel free to find the data table by UIComponent#findComponent() instead and to set the filename in action method only. The above code is just exemplary.

这篇关于p:dataExporter不能识别p:cellEditor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆