jasperserver boolean parameter do not works properly

I have an string parameter with the following expression:

$P{One_Week}.toString().equals ("true") ? new String("2016-07-01"):new String("2016-07-02")

The parameter One_Week is defined as java.lang.Boolean

This expression is working properly in Jasper Studio 6.2.0, however when I try to use the same report in JasperServer, I'm getting the following error:

Error evaluating expression for source text: $P{One_Week}.toString().equals ("true") ? new String("2016-07-01"):new String("2016-07-02")

java.lang.Thread.run(Unknown Source) Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean 

 

Any idea why this works properly in studio but is not working on server?

 

Thanks in advance.

iscoscar's picture
313
Joined: Nov 17 2015 - 10:17am
Last seen: 1 month 3 weeks ago

Also tried the following expresion:

$P{One_Week}?  new String("2016-07-01"):new String("2016-07-02")

is the same problem, It's working on Studio but do not works on Server  (same erros message)

iscoscar - 6 years 9 months ago

one more expression with the same result, it works on Studio but not in Server:

new Boolean($P{One_Week}.toString()).equals("true")?  new String("2016-07-01"):new String("2016-07-02")

iscoscar - 6 years 9 months ago

 

Thanks @Hozawa

very simple solution, adding the Parenthesis on the condition works.  Jasper Studio dont require that format.

here the solution:

($P{One_Week}.toString().equals ("true")) ? new String("2016-07-01"):new String("2016-07-02")

 

Thanks,

 

iscoscar - 6 years 9 months ago

5 Answers:

Did you try putting the evaluation expression in paranthesis

($P{One_Week}.toString().equals ("true")) ? new String("2016-07-01"):new String("2016-07-02")

hozawa's picture
176469
Joined: Apr 24 2010 - 4:31pm
Last seen: 3 years 11 months ago

Hi,

you can use( Your boolen field == Boolean.TRUE ? "Expression 1":"Expression 2")

hope this will help

 

AnilSaini's picture
509
Joined: Feb 28 2016 - 7:34pm
Last seen: 5 years 5 months ago

Thansk for your reply @AnilSaini 

I'm testing using your example... same result, works on Studio but not in Server.  Error message:

Error evaluating expression for source text: $P{One_Week} == Boolean.TRUE ? new String("2016-07-01"):new String("2016-07-02")

iscoscar's picture
313
Joined: Nov 17 2015 - 10:17am
Last seen: 1 month 3 weeks ago

Seems like $P{One _Week} is a type String and not a Boolean in JasperReports Server. 

Try,

($P{One_Week}.toLowerCase().equals ("true")) ? new String("2016-07-01"):new String("2016-07-02")

hozawa's picture
176469
Joined: Apr 24 2010 - 4:31pm
Last seen: 3 years 11 months ago

Thanks @hozawa

The paramter One_Week is Boolean, below the section where I'm declaring the type

<parameter name="One_Week" class="java.lang.Boolean">
<defaultValueExpression><![CDATA["False"]]></defaultValueExpression>
</parameter>
 
I have tried the expression you suggested but I'm getting an error:
    The method toLowerCase() is undefined for type Boolean.
 
iscoscar's picture
313
Joined: Nov 17 2015 - 10:17am
Last seen: 1 month 3 weeks ago
Feedback
randomness