How to use a condition in a static text field? - jasper-reports

I'm using condition to print field values.My condition is if isList == "list" then print value of region_name.Following codes works fine.
<textFieldExpression><![CDATA[($F{isList} == "list" ? "" : $F{region_name})]]></textFieldExpression>
But now I need to print static text using condition too. When I'am using same method,it doesn't work.It shows "($F" instead of static text.
<text><![CDATA[($F{isList} == "list" ? "Region:" : "")]]></text>
What is wrong ? How I can fix it ?

Related

I have a query that returns '[ ]'. I want it to be shown on a widget as not having any value, how do I do this?

I have a query in my flutter app that should return empty if 'archived' 'isNull' is set to true. I accomplished that, but the issue I'm having now is the fact that the query returns empty (i.e [ ]). And on the widget, I want this to be shown as not having any value but instead, an empty pair of brackets '()' keep showing up.
I have tried checking for when query data equals null, something like this:
if (queryResult.data == null){
// The idea is for it not to just return '()' as the value
value = null;
}
else{
value = queryResult.data;
}
And also:
if (queryResult.data == []){
value = null;
}
else{
value = queryResult.data;
}
How do I go about this? Thanks in advance.
If "data" is a list why not try data.isEmpty() ? And also if you only need to avoid the brackets (dirty fix alert ⚠️) whatever you did it's returning a string value '()' then you check that
if(yourResults == '()' )value == null;
And please add more details for a better answer .

Drool DRL contains

This my When condition
$cla : cashliquidassets(
entity == "AU001",
asset_liability_indicator == "A",
product_group.contains('Loans','Bankofindia'),
product.contains("DS"),
counterparty_resident_indicator == "AU",
counterparty_type.contains("DS"),
related_entity == "Y"
)
I am getting an error at
Unable to Analyse Expression product_group.contains("Loans","Bankofindia")
Any Suggestions
Without your class model is hard to tell, but assuming that cashliquidassets.product_group is a String, you are trying to use an unexisting method String.contains(String, String).
One option would be to use an OR or and AND between 2 contains:
...
(product_group.contains('Loans') || product_group.contains('Bankofindia')),
...
or
...
product_group.contains('Loans'),
product_group.contains('Bankofindia'),
...
Another option could be to use the matches operator with a regular expression.
Hope it helps,

Drools MVEL Dialect - Semi-Colon Requirement

I am just curious as to why my Eclipse Drools compiler (6.5.0) requires semi-colons at the end of statements in the For loop, as below:
Map businessRulesRequest = $root.containsKey("BusinessRulesRequest") ? $root.get("BusinessRulesRequest") : null
Map quoteRequest = businessRulesRequest!=null && businessRulesRequest.containsKey("QuoteRequest") ? businessRulesRequest.get("QuoteRequest") : null
List resultsByKey = quoteRequest!=null && quoteRequest.containsKey("resultsByKey") ? quoteRequest.get("resultsByKey") : new ArrayList()
for (Map search : resultsByKey) {
Map searchInfo = (search.containsKey("searchInfo") ? search.get("searchInfo") : null);
String searchName = searchInfo!=null && searchInfo.containsKey("searchName") ? searchInfo.get("searchName").toString() : "";
List results = (searchName=="quotesMotor" && search.containsKey("results") ? search.get("results") : new ArrayList());
}
If I remove the semi-colons from the first or second lines in the For loop, I get an "unexpected token" error, but not if I remove it from the last line in the loop.
Is it due to Drools evaluating RHS lines as a single statement and so they must be separated inside any loops?
Note: I understand it is not best practice to code assuming semi-colons are not required, however I came across this issue while experimenting and am just interested to know the reason for the compiler error. Thanks.
I guess the answer is because of MVEL itself. Drools may be delegating the entire chunk of code to MVEL to evaluate and execute.
According to this guide, in MVEL the use of a semi-colon is not mandatory in cases where you have 1 statement, or in the last statement of a script.
Hope it helps,

Why does my ternary operator give a different result to an if else?

The problem I am having is I am trying to use ternary operators over if else for smaller code but when using it in my case it is returning a different result than if I use an if else.
The problem code is below;
If Else
if(string.IsNullOrEmpty(jn["LARM"].Value))
pm.ItemLeftArm = null;
else
pm.ItemLeftArm = jn["LARM"];
Ternary
pm.ItemLeftArm = string.IsNullOrEmpty(jn["LARM"].Value) ? null : jn["LARM"];
The jn["LARM"] is a json node from simpleJSON and it is either a number e.g. "0" or nothing e.g. "".
It returns null form the if else but it returns the jn object which transforms from "" into 0.
Im not sure why Im getting this issue.
The code is ok, the problem must be in the JSON. Have you tried logging the jn["LARM"].Value just before the terniary operator in order to be sure that the value is null/empty or not?
BTW, why are you using simpleJSON instead of the new Unity integrated JsonUtility?

Hide static text field when $P{} is ""

I'm using iReport 4.7.1. The report contains a static field "Date Validated:" and a text field "$P{DATE_VALIDATED}" which i can confirm is "" empty. I want to hide "Date Validated: " text when $P is empty.
I have tried the following so far:
I have added the following line in the property (print when expression) of the static field which has static text "Date Validated: " :
$P{DATE_VALIDATED} == "" ? new Boolean(false) : new Boolean(true)
I also tried the following variations:
$P{DATE_VALIDATED} == "" ? "" : "Date Validated:"
$P{DATE_VALIDATED} == "" ? Boolean.FALSE : Boolean.TRUE
But static field is still showing up. I also tried putting just Boolean.FALSE to hide it completely to test and see but text is still showing up.
You can try the below expression in print when condition
!$F{DATE_VALIDATED}.isEmpty() && $F{DATE_VALIDATED} != null && $F{DATE_VALIDATED} != ""
Hope this should solve your problem.
Thanks viki888 for the quick answer, that's an improvement to what i am trying to do, i'll up vote it, but the problem in my situation was i wasn't Compiling the Report after saving it, because i didn't know i had to and there isn't an obvious option/menu item or icon except tiny little hammer on the toolbar on designer window that says Compile Report... :)
So in my case compiling the report solved the problem for me. and
$P{DATE_VALIDATED} == "" ? Boolean.FALSE : Boolean.TRUE
is working fine.