-1

I have a question: how to set default value of the parameter i JasperReport's report? I have tried sth like this:

<parameter name="where" class="java.lang.String" isForPrompting="false">
    <defaultValueExpression><![CDATA[1 = 1]]></defaultValueExpression>
</parameter>

and include this parameter to my queryString:

<queryString>
    <![CDATA[SELECT *
      FROM "TABLE"
      where $P{where}]]>
</queryString>

But I have an error. I also tried to set this value in java, for instance 1.equals(1) but it still doesn't work. I have to set in this parameter a condition which is always true. How to do this?

Alex K
  • 22,315
  • 19
  • 108
  • 236
pulpet112
  • 43
  • 2
  • 10

2 Answers2

0

it's not work, you try build dynamic sql. Jasper not support dynamic sql.

My solution:

<parameter name="where" class="java.lang.String" isForPrompting="false">
    <defaultValueExpression><![CDATA[1]]></defaultValueExpression>
</parameter>

and query:

<queryString>
<![CDATA[SELECT *
  FROM "TABLE"
  where ('1' = $P{where} or any_column = $P{where})]]>

Piotr Rogowski
  • 3,642
  • 19
  • 24
0

I have already solved this problem. Solution is simple. I have done everything right but <![CDATA[1 = 1]]> should be replaced by <![CDATA["1 = 1"]]>. Second step is to ad "!" after $P declaration like this: where $P!{where}. And now everything works fine. I hope this help others.

pulpet112
  • 43
  • 2
  • 10