jasperserver boolean parameter do not works properly
Posted on August 10, 2016 at 10:50pm
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.
Joined: Nov 17 2015 - 10:17am
Last seen: 1 month 3 weeks ago
Posted on August 11, 2016 at 2:49pm
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")
Joined: Apr 24 2010 - 4:31pm
Last seen: 3 years 11 months ago
Posted on August 10, 2016 at 10:54pm
Hi,
you can use( Your boolen field == Boolean.TRUE ? "Expression 1":"Expression 2")
hope this will help
Joined: Feb 28 2016 - 7:34pm
Last seen: 5 years 5 months ago
Posted on August 10, 2016 at 11:02pm
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")
Joined: Nov 17 2015 - 10:17am
Last seen: 1 month 3 weeks ago
Posted on August 11, 2016 at 1:23am
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")
Joined: Apr 24 2010 - 4:31pm
Last seen: 3 years 11 months ago
Posted on August 11, 2016 at 8:58am
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.
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)
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")
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,