Is it possible to create fields in Jasperreports report without setting them beforehand?

Asked

Viewed 82 times

0

Hi, I have a jTable where the user defines which fields will appear on it, this way I would need several reports JasperReports, one for each possible combination (chosen by jRadioButtons). There is a way to "send" the report fields(their names) beyond the parameters , without creating the fields previously in the report JasperReports?

Print by Jtable:

inserir a descrição da imagem aqui

Here’s the thing, there’s some jRadioButtons where the user chooses which fields he wants to appear on jTable (after the populated jTable), for example he may want to appear only "code" and "name". Hence the need for several reports, with different fields, these fields I wanted to "send" and not have them created in the report in advance. I’m trying something with DynamicReports, but I wore a HQl for the report containing the jTable complete, without the user choosing what they want to view, I’m trying to adapt the code .

Method generating the report of jTable 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 jRadioButton

 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);
        }
    } 
  • Is there any way you can get a print of your Jtable for me to visualize and better understand your problem? .

  • @Julio Cesar da Silva Barros, I added some information.

  • I decided to change the approach and did it with http://www.dynamicreports.org/ but if anyone knows anything about doing with Jasperreports, would like to try.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.