Search code examples
jsf-2primefacesdatatableparameter-passingexporter

how can i pass a DataTable as a parameter from view to backing bean?


I'm implementing a custom pdf exporter, but i need to pass my datatable from the view to my backing bean, but i dont know how to do it.

in the view i'll have a commandlink that is going to look like this:

  <h:commandLink action="#{procesos.exportPDF( mytable , 'procesos')}">
     </h:commandLink>

this is the method that receive a DataTable as a parameter:

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

anyway.. what i want to do is to modify column width with a custompdf exporter because dataexporter and the exporter extension of primefaces does not allow that function, so if someone knows or have a custom pdf exporter that allow that it would be much appreciated to show a little bit (better all ) of the code :)!

thanks.


Solution

  • I had the same problem. I did not pass the table directly. I just passed the ids of the form and the table and used the findComponent

    FacesContext context = FacesContext.getCurrentInstance();
    UIViewRoot viewRoot = context.getViewRoot();
    
    // find table by form- and table-id
    UIComponent component = viewRoot.findComponent(formId).findComponent(tableId);
    DataTable table = (DataTable) component;