Generate report only with data passed via Ireports parameter

Asked

Viewed 549 times

-1

Normally we generate report by Ireports based on database query, only now I come across the following question, I will assemble a report based on the data shown in the customer’s look, in case it is redundant to fetch the information again in the bank.

I did a simple test 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 as soon as I make his call.

 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 when executing it returns blank.

  • Are you passing at least one element in the Collection of your datasource? Something like: Jrbeancollectiondatasource ds = new Jrbeancollectiondatasource(collectionComUmaInstance); ... Jasperprint prt = Jasperfillmanager.fillReport(getClass(). getResourceAsStream("/" + wayRelatory), parameters, ds);

1 answer

0

In ireport, you can add parameter via code or via application: Follow 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>

Ai through the java you call the code

HashMap valores = new HashMap();
valores.put("cdmov",cdmov);
  • But in case I do not want to make a query via database.

  • then you call only the parameter

  • I will illustrate in the question.

Browser other questions tagged

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