Is it possible to create fields in JasperReports report without setting them in advance?

0

Hello, I have a jTable where the user defines which fields will appear in it, so I would need several JasperReports reports, one for each possible combination (chosen through jRadioButtons ). Is there a way to "send" the report fields (their names) in addition to the parameters, without creating the fields previously in the report JasperReports ?

Print from JTable:

Hereisthefollowing,ithassomejRadioButtonswheretheuserchooseswhichfieldshewantstoappearinjTable(afterthepopulatedjTable),forexamplehemaywanttoseeonly"code" and "name". Hence the need for several reports, with different fields, these fields I wanted to "send" and did not have them created in the report in advance. I'm trying something with DynamicReports , however I used a HQl for the report containing jTable complete, without the user choosing what to view, I'm trying to adapt the code.

Method that generates report of% complete%:

private void jBGerarRelatorioActionPerformed(java.awt.event.ActionEvent evt) {                                                 

        DefaultTableModel model = (DefaultTableModel) jTableResultado.getModel();
        JRTableModelDataSource dataSource = new JRTableModelDataSource(model);

        String path = getClass().getResource("/relatorios/Teste.jrxml").getPath();
        JasperReport report = null;
        try {
            report = JasperCompileManager.compileReport(path);
        } catch (JRException ex) {
            Logger.getLogger(ConsultasView1.class.getName()).log(Level.SEVERE, null, ex);
        }
        Map<String, Object> parametros = new HashMap<String, Object>();
        JasperPrint jp = null;
        try {
            jp = JasperFillManager.fillReport(report, parametros, dataSource);
        } catch (JRException ex) {
            Logger.getLogger(ConsultasView1.class.getName()).log(Level.SEVERE, null, ex);
        }
        JasperViewer jrv = new JasperViewer(jp, false);
        jrv.setVisible(true);

    }

Event of jTable

 private void jRadioCodigoItemStateChanged(java.awt.event.ItemEvent evt) {                                              
        if (evt.getStateChange() == ItemEvent.SELECTED) {
            jTableResultado.getColumnExt("Código").setVisible(false);
        } else if (evt.getStateChange() == ItemEvent.DESELECTED) {
            jTableResultado.getColumnExt("Código").setVisible(true);
        }
    } 
    
asked by anonymous 08.04.2016 / 04:36

0 answers