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

Elseif In Expression Editor


maruthu.u

Recommended Posts

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Just use the short java syntax for that:

$F{YourFieldX}.equals("Microsoft") ? "BigButBuggy" :  "OthersArePerhapsBetter" [/code]

of course you can also build nested if-then-elses (use brackets for more readability):

$F{YourMoneyBag} < 0 ? "Ooops negative is bad" : ( $F{YourMoneyBag} <= 100 ? " ok positive but could be more": "more than 100 - well done" )[/code]

hth + regards

C-Box

Link to comment
Share on other sites

it's also great method,

$F{result}.equalsIgnoreCase("approved") ? "Approved" :
($F{result}.equalsIgnoreCase("not_suitable") ? "Not suitable" :
($F{result}.equalsIgnoreCase("hold") ? "Hold" :
($F{result}.equalsIgnoreCase("production_trial") ? "Go to production trial":""  )))

Finaly when Not satisfied any condition display  "" empty.

i'm using this method to complete the process.

Link to comment
Share on other sites

Be aware that if your Field named "result" is in java or from your query just  null then you will get a NullPointerException that is internally ignored by JasperReports by default. :-O  Then your expression won't work as expected!

So that's why it's (always) better to turn the equals comparisons to make it null-safe:

"approved".equalsIgnoreCase($F{result}) ....[/code]

;-)

Or just use the StringUtils from Apache, that are also more "null-resistant" and also available in JasperReports classpath.

Just my two cents

C-Box

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...