Generate report only with data passed via parameter IReports

0

Normally we generate report by IReports based on query to the database, but now I come across the following question, I will assemble a report based on the data shown in the client's visual, in case it is redundant to fetch the information back into the database.

I made a simple test by passing 1 information via parameter and trying to generate a view.

But it did not generate any page, I believe it is something simple but I am not able to generate this output.

In the report I only have one parameter created and added in the detail field in it.

And that's how I call it.

 public void ImpressaoRelatorio() {

    InputStream inputStream = getClass().getResourceAsStream("RelatorioParametro.jasper");

    Map<String, Object> parametros = new HashMap<String, Object>();

    parametros.put("descProduto", "Produto Teste");


    try {

        ReportUtils.openReport("Relatorio Produto teste", inputStream, parametros,
                ConnectionFactory.getAgilConnection());

    } catch (SQLException exc) {
        exc.printStackTrace();
    } catch (JRException exc) {
        exc.printStackTrace();
    }
}

But running it returns blank.

    
asked by anonymous 10.07.2017 / 16:18

2 answers

0

In ireport, you can add parameter via code or via application: Here's an example via code

<parameter name="cdmov" class="java.lang.Object" isForPrompting="false">
        <defaultValueExpression><![CDATA[new Long(12883)]]></defaultValueExpression>
    </parameter>
    <queryString>
        <![CDATA[SELECT
         P.NOME
          FROM
      PESSOA P
  WHERE
   AND  M.CD_PESSOA = $P{cdmov}]]>
    </queryString>

Then by java you call the code

HashMap valores = new HashMap();
valores.put("cdmov",cdmov);
    
10.07.2017 / 16:41
0

Are you passing at least one element in the collection of your datasource?

Something like:

JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(colecaoComUmaInstancia);

...

JasperPrint prt = JasperFillManager.fillReport(getClass().getResourceAsStream("/" + caminhoRelatorio), parametros, ds);
    
10.07.2017 / 17:49