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

compare strings?


kinny

Recommended Posts

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!

Link to comment
Share on other sites

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!:)

Link to comment
Share on other sites

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

Error compiling the Scriptlet Java source.

net.sf.jasperreports.engine.JRException:ÂErrorÂcompilingÂreportÂjavaÂsourceÂfilesÂ:ÂC:DocumentsÂandÂSettingsKinnyDesktoptestScriptlet.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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

and under Element, it says: /jasperReport???? (from the Problems(1) tab).

 

attached is the code.

Code:

import java.util.*;
import net.sf.jasperreports.engine.*;

public class test extends it.businesslogic.ireport.IReportScriptlet {


public test() {
long l1 = 10;
long l2 = 20;
long difference = l2 - l1;
}

}

also, my iReport file is called: test.jrxml

 

oh yeah, the error I get is:

Compiling to file... C:Documents and SettingsKinmonDesktoptest.jasper -> C:Documents and SettingsKinmonDesktoptest.java
net.sf.jasperreports.engine.design.JRValidationFault@636a7e java.lang.ClassNotFoundException: C:Documents and SettingsKinmonDesktoptest.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 SettingsKinmonDesktoptest.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)
Compilation running time: 266

 

 

Thank you very much codyjasperForge. You've been very helpful! :)

Post edited by: kinny, at: 2007/07/11 13:36

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