Hide static text field when $P{} is "" - jasper-reports

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.

Related

ZKOSS version 7.0.0 checkbox or clear radiogroup

Good morning, everyone,
I am having a problem with the handling of two checkboxes which should be mutually exclusive, on the page we cannot put an id because multiselection is provided.
enter image description here
Here the zkoss code:
<cell colspan="2">
<checkbox
label="${labels.label.giaAddebitata}"
checked="#load(each.flagAddebitata eq '1')"
onCheck="#command('addebitata', fladd=event.checked,idPer=each.idPerizia )"
onFocus="#command('manageList', idPer=each.idPerizia)"
disabled="#load(each.statoContabile eq 4 ? true : false)"/>
</cell>
<cell colspan="2">
<checkbox
label="${labels.label.nonAddebitare}"
checked="#load(each.nonAddebitare eq '1')"
onCheck="#command('nonaddebitata',flnoadd=event.checked, idPer=each.idPerizia)"
onFocus="#command('manageList', idPer=each.idPerizia)"
disabled="#load(each.statoContabile eq 4 ? true : false)"/>
</cell>
and the java functions
#Command
#NotifyChange ({ "flagAddebitata","nonAddebitare", "selectedRic"})
public void addebitata(#BindingParam("fladd") boolean fladd,#BindingParam("idPer")int idPerizia ) {
boolean addebitata = fladd;
selectedRic = new HashSet<AddebitoClienteViewDTO>();
for(AddebitoClienteViewDTO add : carList) {
if(add.getIdPerizia() == idPerizia) {
add.setFlagAddebitata(booleanToString.apply(fladd));
selectedRic.add(add);
}
}
logger.debug("SELECTEDRIC non addebitare " + selectedRic);
logger.debug("addebitata funzione " +addebitata);
}
#Command
#NotifyChange ({ "nonAddebitare", "selectedRic"})
public void nonaddebitata(#BindingParam("flnoadd") boolean flnoadd,#BindingParam("idPer")int idPerizia ) {
boolean nonaddebitata = flnoadd;
selectedRic = new HashSet<AddebitoClienteViewDTO>();
for(AddebitoClienteViewDTO add : carList) {
if(add.getIdPerizia() == idPerizia) {
add.setNonAddebitare(booleanToString.apply(flnoadd));
selectedRic.add(add);
}
}
logger.debug("SELECTEDRIC non addebitare " + selectedRic);
logger.debug("nonaddebitata funzione " +nonaddebitata);
}
We tried using the && != " the != alone and adding another binding param to the java functions.
The result we want to achieve is that if one check is clicked the other if it is already selected loses the check.
Alternatively we tried the radiogroup but it does not allow the non-selection of radioboxes, one is always mandatory.
Is there a way to clear the radiobutton without a java clear function?
Thanks
That's a lot of code and hard to turn into a reproducing case due to all of the extra objects, so I'll focus more on the functional requirement.
From your description, I understand that what you want to create is a system in which you can either select "A", "B" or "none".
There is some unspecified behavior in there (like if "A" is selected, can I select "B" and automatically clear selection on "A"? Or does having "A" selected mean that "B" is non-selectable).
From your stated requirement, the component I would choose to express that structure is a dropdown menu with 3 choices ("not selected", "A", "B"), but that might not be what you are trying to achieve with the UI design here?
If you want to make something like that using checkboxes, you may want to keep a single state for the selection status, and a command to update the selection status.
See a simple code sample here: https://zkfiddle.org/sample/hb7f7k/1-Another-new-ZK-fiddle
The left 2 checkboxes work on a "unselect others if selected" workflow.
The right 2 checkboxes work on a "cannot select others while selected, but can unselect" workflow.
Note: that sample is a "bare minimum" implementation. In a real case, you'd improve it by factorizing the code, making it into a template, etc. rather than declaring these values inline.

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?

How to use a condition in a static text field?

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 ?

Check if text binded to a control is null

I'm trying to check if I'm binding a null data on a controller. If the data is null, I need to not show the label as well as the binded data.
Below is my code right now.
var oMatNrRow1 = new sap.ui.commons.layout.MatrixLayoutRow();
control1 = new sap.ui.commons.Label({
text : Appcc.getText("MATERIAL_NO") + ":"
});
matrixCell1 = new sap.ui.commons.layout.MatrixLayoutCell();
matrixCell1.addContent(control1);
control = new sap.ui.commons.Label();
control.bindProperty("text", "matnr");
matrixCell1.addContent(control);
oMatNrRow1.addCell(matrixCell1);
vendorTable.addRow(oMatNrRow1);
I have tried control.getProperty("text") but it only returns null when it should have return a number if matnr is not null.
I also tried formatter. I will have no problem with formatter if matnr is not null. But if it is null, the point is to destroy/delete contents of both matrixCell1 instances. In my code below, addition of matrixCell1 content will still push through.
...
formatter: function(matnr){
if (matnr !== ''){
return contract
} else{
matrixCell.destroyContent();
}
});
matrixCell1.addContent(control);
oMatNrRow1.addCell(matrixCell1);
vendorTable.addRow(oMatNrRow1);
Not sure if you can move the ff code inside if statement
matrixCell1.addContent(control);
oMatNrRow1.addCell(matrixCell1);
vendorTable.addRow(oMatNrRow1);
Any ideas are appreciated.
I would also suggest to user the visible property.
Are you aware of conditional binding of UI5? Using them you do not need the formatter at all in that case. see
Found a workaround on my issue. It was a simple if else condition. For the if statement, I just added data[j].matnr and it worked! I also noticed that this was how SAP implemented the behavior also e.g. oSearchViewData.description.