Jump to content

If, then, else and case statements in fields


pinkman

Recommended Posts

We are upgrading from Crystal to iReport. One of the main hurdles is learning the syntax for field functions (not all users are Java developers). So far it looks like the Crystal syntax is easier to use, making it the only good thing about Crystal IMHO :).

 

In particular, is there a nicer way to do if/else and case statements other than what is recommended here: http://www.jasperforge.org/index.php?option=com_joomlaboard&Itemid=&func=view&catid=9&id=12491#12491

. I would like to get away from having to make users do it in SQL, as case statements in SQL are often vendor specific. And using the (true):then?else syntax gets unwieldy when you have more than a few different options.

 

Thanks for reading this, and any ideas would be appreciated :).

 

Simon.

 

Post edited by: pinkman, at: 2008/02/19 02:09

 

Post edited by: pinkman, at: 2008/02/19 02:10

Post edited by: pinkman, at: 2008/02/19 02:11

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

"(boolean expression) ? if true : if false" is the only if/then/else//case logic for the fields in ireport, it does get complicated and hard to maintain with the increase of possible outcomes, but you can get used to it. Also, you have standard Java operators (&&, ||, ==, !=, ....) that you can combine, and there are methods of individual classes (String.equals() for example). Once you start designing the report you will see what option (combination) you are most comfortable with, but I think you won't avoid boolean?true:false :)
Link to comment
Share on other sites

Thanks for the reply Pedja. In that case, does anyone know of any work being done to make the functional language a bit more user friendly/powerful? My business users will be happy so long as I can tell them usability will improve.

 

For now, I will recommend that they switch the language to Groovy, which helps a bit as most of my users don't understand OOP much, if at all. It would be nice if we could harness the full power of Groovy and use proper if else statements. It does seem to me to be the biggest shortfall of Jasper.

 

If there isn't any work being done on it, is there somewhere I can report a request? There is even a possibility I could offer my programming services.

Link to comment
Share on other sites

It seems to be the way the report is compiled, it is compiled to use an inline statement, for instance:

Code:

value = (java.lang.String)((true ? "true" : "false" ));

 

Knowing this, you can hack the expression to make it more scriptable like so:

Code:
[code]
""«»);
boolean asd = true;
if (asd)
value = "www";
else
value = "asd"; (""

 

Just an observation :)

 

I have raised a feature request: http://jasperforge.org/sf/go/artf3040

 

Link to comment
Share on other sites

  • 3 weeks later...

Hi,

 

We are generally opposed to any attempt to make the report templates more scriptable than they are today.

Today, expressions are Java or Groovy expressions.

We don't want people to be able to write sequences of statements like the if/else you mentioned.

If we do so, they would be encouraged to write entire programs inside a JRXML template.

And report templates are just not the best way to write code. Why someone would put Java code into an XML file for which there is no support for syntax highlighting, code completions and code check.

There are plenty of Java editors there and this is because Java code should stay in *.java files, not *.jrxml files.

 

So what we tell people is that when expression tend to become more complicated, they should put all that complicated code into an utility class and then from the report expression itself they only make calls to that external utility method, keeping the report expression as simple as possible, while isolating the complex code in dedicated Java source files that can be edited with an IDE, compiled and maintained properly, like any other Java program.

 

I hope this helps.

Teodor

Link to comment
Share on other sites

Hi Teodor,

 

Thanks for taking the time to reply. I understand your concerns, and I too agree that complicate logic should reside somewhere outside of the report itself. For the most part I think logic can be tucked away into the SQL. Unfortunately getting our business users to create stand-alone Java files is out of the question for us; they are business users after all and not developers. For what we need it for it would be overkill anyway.

 

My problem is that I am trying to convince them to switch from Crystal Reports to Jasper. I have solid experience with Crystal, and a bit of experience with BIRT; both of which allow general scripting for the report functions, see: http://www.eclipse.org/birt/phoenix/project/notable2.0.php#jump_13

. Our users will not be writing overly complex logic in the functions, but really need simple things like case statements and if-else statements.

 

I am training our users now, and as they get used to it they are finding the lack of power of the Jasper functions frustrating - they are loving everything else :). In the long run though, from my experience I believe making this change would help migrate more people onto Jasper and away from Crystal and other products.

 

Kind Regards,

Simon.

Link to comment
Share on other sites

  • 5 years later...

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