Jump to content
We've recently updated our Privacy Statement, available here ×

Can anyone please help explain the basics of jasper expressions?


n d Jaspersoft

Recommended Posts

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.

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...