Can anyone please help explain the basics of jasper expressions?

0

Hi, 

What does the :, ? or null mean in an expression? 

Eg.  ${f684_v} == null && ${f685_v} == null ? " " : (${f684_v} == null ? "-" : ${f684_v}) + " / " + (${f685_v} == null ? "-" : ${f685_v})

What does the above mean?

Any help or even link to a easy to understand website would be so appreciated.

Thank you.

n d Jaspersoft's picture
Joined: Jun 25 2019 - 3:32am
Last seen: 1 month 3 weeks ago

That is very helpful and very well explained!

And yes, I had already deleted the F from the $F{...} ready for the new language I have to put them in. I will look how to write an IF Then Else epression in the new language. Thank you.

What about this- ($F{f227_v} != null ? $F{f227_v} : "-") + " / " + ($F{f228_v} != null ? $F{f228_v} : "-")

Is this similar or does the ! mean something?

n d Jaspersoft - 1 month 3 weeks ago

The != means (not equal) 

? means (then)

: means (else)

luked - 1 month 3 weeks ago

Thank you very much luked 

This is a very helpful forum.

n d Jaspersoft - 1 month 3 weeks ago

1 Answer:

1

I'll try do explain:

Its a nested If Then Else expression.

So first <null>... it means in java, not defined... just google for Java null

second, i guess (!?!) you wrote the syntax wrong...it should be  $F{...} and not ${f..} ... so the identifier $F{any_fieldNameOfAQuery}  means a field in a JasperReport.

third the && means a logical AND operator

so your expression means: ( I level up the nested if-thens with fictive numbers)

1. LEVEL

if Field "684_v" AND also Field "685_v" are bot null (remember: null = not defined/initialized) then print an emtpy space character " "

OTHERWISE/ELSE 1. LEVEL

 2. LEVEL

   if just field "684_v" is null, then print a minus character "-"

   OTHERWISE/ELSE 2. LEVEL

   concat the current field value "684_v" with a slash " / " String and 

   3. LEVEL

    if  field "685_v" is null then again a minus char "-"

    OTHERWIESE/ELSE 3. LEVEL

   append the value of field "685_v"

So if both fields are filled you will get something like "Hello / World"  and if one of it's field is null you would either get "-/ World" or the other way  "Hello / -

if both fields are null you just will get an empty space char " "

now a bit more clear?!?! :-)

hth + regards

C-Box

C-Box's picture
1669
Joined: Jul 19 2006 - 5:58pm
Last seen: 1 day 15 hours ago
Feedback
randomness