compare strings?

1
Hello,

I'm a new user to iReport/JasperReports and Java programming.

I have a query name EPL which contains either "FF" or "FE" and it's assigned to $F{EPL}.

What I want to do is:

if $F{EPL} == "FF" then draw the box.

how would I do that?

I see there is a "Print when Expression:"

but how do I write the code?

the following gives me an error:
new Boolean($F{EPL}.equals("FF"))

Many thanks!
kinny's picture
10
Joined: Jul 9 2007 - 11:24pm
Last seen: 12 years 2 months ago

8 Answers:

1
Please post your error...
---> If new Boolean($F{EPL}.equals("FF")) does not work.

Try using

new Boolean($F{EPL}.toString()).equals("FF")

This changes whatever value being returned into it's string equivalent, the checks for comparison. HTH...
codyjasperForge's picture
Joined: Jun 6 2007 - 3:44am
Last seen: 2 years 5 months ago
0
actually, it works! Thanks!

i'm just wondering, what kind of java language does iReports use?

How can't seem to write any if statements and use multiple lines...:

if ($V{checkEPL}) {
$V{starttime} = $F{starttime}.toString();
$V{endtime} = $F{endtime}.toString();
}

Thanks!
kinny's picture
10
Joined: Jul 9 2007 - 11:24pm
Last seen: 12 years 2 months ago
0
iReport uses java coding language, however, if you are writing code that actually does more that 2-5 lines of functionality, then I would recommend that you use a scriptlet to do so. There are limits to what type of statments you may write inside of your 'textfield/group/print when' expressions. Look at the samples to get an idea of what all you can/can't do.
Also, make sure that you have all of the necessary .jar files in the ireport 'lib' directory, and the latest JDK (1.5) to get the most out of your code.
Hope this helps.

For your statement:
if ($V{checkEPL}) {
$V{starttime} = $F{starttime}.toString();
$V{endtime} = $F{endtime}.toString();
}


Try this: ($V{checkEPL} == "true") ? ($V{starttime} = $F{starttime.toString())
: $V{starttime} =
Whatever value you want when 'checkEPL' is false



($V{checkEPL} == "true") ? ($V{endtime} = $F{endtime.toString())
: $V{endtime} =
Whatever value you want when its false



Do this then let me know what happens...

Post edited by: codyjasperForge, at: 2007/07/10 15:36
Post edited by: codyjasperForge, at: 2007/07/10 18:24
codyjasperForge's picture
Joined: Jun 6 2007 - 3:44am
Last seen: 2 years 5 months ago
0
yeah, what i'm trying to do is the following:

Description:

"Start Time": stored in the database as dd/mm/yy hh:mm AM/PM

"Stop Time": stored in the db as dd/mm/yy hh:mm AM/PM

"Duration": the time elapsed from start to stop time. - Not stored in the database. I guess this is where I need to use Scriptlet to calculate the duration.

"Location": stored in the database as (ie:123 Avenue Road)

"EPL": check to see if it's "FF" or "FE"

<Table Header>
Start Time | Stop Time | Duration | Location |EPL
</Table Header>


so basically in the table data, I would like to check if the EPL is FF or FE. If that is true, create a row and add the corresponding fields along with the calculated Duration (elapsed time).

ie:
<Table Data>
10/07/07 11:01 PM | 10/07/07 11:11 PM| 10 min | 123 Avenue Road | FF
</Table Data>

thank you very much for the help codyjasperForge!:)
kinny's picture
10
Joined: Jul 9 2007 - 11:24pm
Last seen: 12 years 2 months ago
0
hmm, i seem to be getting an error.

i simply activated the Scriptlet (with no code) and ran it.

Compiling scriptlet source file... C:\Documents and Settings\Kinny\Desktop\testScriptlet.java
Error compiling the Scriptlet Java source.
net.sf.jasperreports.engine.JRException:ÂErrorÂcompilingÂreportÂjavaÂsourceÂfilesÂ:ÂC:\DocumentsÂandÂSettings\Kinny\Desktop\testScriptlet.java ÂÂÂÂatÂnet.sf.jasperreports.engine.design.JRJdk13Compiler.compileClasses(JRJdk13Compiler.java:119) ÂÂÂÂatÂnet.sf.jasperreports.engine.design.JRAbstractMultiClassCompiler.compileClass(JRAbstractMultiClassCompiler.java:45) ÂÂÂÂatÂit.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:357) ÂÂÂÂatÂjava.lang.Thread.run(UnknownÂSource) CausedÂby:Âjava.lang.ClassNotFoundException:Âcom.sun.tools.javac.Main ÂÂÂÂatÂjava.net.URLClassLoader$1.run(UnknownÂSource) ÂÂÂÂatÂjava.security.AccessController.doPrivileged(NativeÂMethod) ÂÂÂÂatÂjava.net.URLClassLoader.findClass(UnknownÂSource) ÂÂÂÂatÂjava.lang.ClassLoader.loadClass(UnknownÂSource) ÂÂÂÂatÂsun.misc.Launcher$AppClassLoader.loadClass(UnknownÂSource) ÂÂÂÂatÂjava.lang.ClassLoader.loadClass(UnknownÂSource) ÂÂÂÂatÂjava.lang.ClassLoader.loadClassInternal(UnknownÂSource) ÂÂÂÂatÂjava.lang.Class.forName0(NativeÂMethod) ÂÂÂÂatÂjava.lang.Class.forName(UnknownÂSource) ÂÂÂÂatÂnet.sf.jasperreports.engine.util.JRClassLoader.loadClassForRealName(JRClassLoader.java:163) ÂÂÂÂatÂnet.sf.jasperreports.engine.design.JRJdk13Compiler.compileClasses(JRJdk13Compiler.java:81) ÂÂÂÂ...Â3Âmore
Compilation running time: 110
kinny's picture
10
Joined: Jul 9 2007 - 11:24pm
Last seen: 12 years 2 months ago
0
Remember that in java language, a newly compiled classname MUST match its filename. So say your filename is abc.java, Then the scriptlet class name must be: public class abc extends...

Also, if you are using the internal scriptlet editor, make sure the scriptlet file is saved in the same directory as your .jrxml file(same dir as your report). Finally, there is an option under the 'Options' menu called 'Classpath'. Make sure that you have added the correct directories to it. (tools.jar, etc.)
codyjasperForge's picture
Joined: Jun 6 2007 - 3:44am
Last seen: 2 years 5 months ago
0
hmm, i seem to be still having the same problem? I added the correct directories & .JAR files under my Classpath. The problem is:
java.lang.ClassNotFoundException:C:\Documents and Settings\Kinmon\Desktop\test.java
and under Element, it says: /jasperReport???? (from the Problems(1) tab).

attached is the code.
Code:
<br />
import java.util.*;<br />
import net.sf.jasperreports.engine.*;<br />
<br />
public class test extends it.businesslogic.ireport.IReportScriptlet {<br />
<br />
<br />
   public test() {<br />
      long l1 = 10;<br />
      long l2 = 20;<br />
      long difference = l2 - l1;<br />
   }<br />
<br />
}<br />
</td></tr></tbody></table><br />
also, my iReport file is called: test.jrxml<br />
<br />
oh yeah, the error I get is:<br />
<table cellpadding="0" cellspacing="0" align="center" width="525" bgcolor="#cccccc"><tr><td><br />
  Compiling to file... C:\Documents and Settings\Kinmon\Desktop\test.jasper -> C:\Documents and Settings\Kinmon\Desktop\test.java<br />
net.sf.jasperreports.engine.design.JRValidationFault@636a7e java.lang.ClassNotFoundException: C:\Documents and Settings\Kinmon\Desktop\test.java Line: 20, Column: 29 JRXML Element: /jasperReport  net.sf.jasperreports.engine.design.JRValidationException: Report design not valid :       1. java.lang.ClassNotFoundException: C:\Documents and Settings\Kinmon\Desktop\test.java     at net.sf.jasperreports.engine.design.JRAbstractCompiler.verifyDesign(JRAbstractCompiler.java:260)     at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:144)     at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:586)     at java.lang.Thread.run(Unknown Source) <br />
Compilation running time: 266</td></tr></table><br />
<br />
<br />
Thank you very much codyjasperForge.  You've been very helpful! :)<br>Post edited by: kinny, at: 2007/07/11 13:36
kinny's picture
10
Joined: Jul 9 2007 - 11:24pm
Last seen: 12 years 2 months ago
0
One other possibility is to insert the fully qualified classname into the .jrxml source. Under <jasperReport> element there should be an option called 'ScriptletClass'=

1. Either remove it completely and save
2. Enter the full classpath to the scriptlet class.
codyjasperForge's picture
Joined: Jun 6 2007 - 3:44am
Last seen: 2 years 5 months ago
Feedback