Question

I work with Primefaces 4-SNAPSHOT and I have some DataTables with <h:graphicImage> in them which I would like to export into different documents.

The fix that is desribed in p:dataExporter does not recognize p:cellEditor

which is supplied by BalusC works fine for the ExcelExporter, but does not work in the same way fot the CSVExporter.

I get NPE when I try to create the document.

I tried to remove the first lines of Code from the Extend-Class, because I have no CellEditor-Elements. This sort of works. It has no NPEs bus this gives me a document with the toString() of the graphicImage and the alt value.

The Extended-Class is this:

public class ExtendedCSVExporter extends CSVExporter 
{

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

And I call it like described in the referenced topic

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

The column of the Table looks like this:

<p:column sortBy="state">
    <f:facet name="header">
        <h:outputText value="State">
    </f:facet>
    <h:graphicImage id="stateImg" name="state.png" library="icons" value="#{bean.state} />
    <p:tooltip for="stateImg" value="Allowed" showEffect="fade" hideEffect="fade" />
</p:column>

For the Excel export this works fine, and the value which is taken for the image is the value of the tooltip because the graphic image has no alt-value. But this does not work for CSV files

What I get in my document for pageOnly is: "javax.faces.component.html.HtmlGraphicImage@23e645d8AltText"

For the whole Table I get a NPE

Any suggestions how to fix this?

Was it helpful?

Solution

Okay I know have found a solution to my problem.

I just override the HtmlGraphicImage.
I modified the Extended-Class so the GraphicImage always returns an empty String and I fetch the value of the tooltip.

So the Extende-Class looks like this:

public class ExtendedCSVExporter extends CSVExporter 
{

@Override
protected String exportValue(FacesContext context, UIComponent component)
{
    if (component instanceof HtmlGraphicImage) 
    {
        return "";
    }
    else 
    {
        return super.exportValue(context, component);
    }
}

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top