JasperReport/iReport useful basic technique.
When I do reporting. There are some basic things that one commonly will do.
No matter I am using Crystal Report or Jasper Report of other reporting tools.
1. some statistic result, usually I do this with parameter passing.
2. some mapping to make the data more human readable.
3. sub-report dataset. a little complex, not discuss in this post.
The first one is the easiest in Jasper Report. Just pass a parameter map when you fill the report with data.
HashMap paramMap = new HashMap();
paramMap.put("NUMBER_ADMISSION",attendanceList.size());
reportInstance = JasperCompileManager.compileReport("c:/jasperXml/admissionReport0613.jrxml");
jasperPrint = JasperFillManager.fillReport(reportInstance,paramMap,new JRBeanCollectionDataSource(attendanceList));
This pass the number of records as a parameter. Many report have this kind of field.
Then you can get is in the report by $P{keyOfMap}.
2. the second one is a little bit tricky. Due to iReport not so clear importing and classpath handling.
I am still not very sure which step(s) make this right. but I will tell you all that I’ve done to make it work.
i. you need to have a class with a static method to do the transformation for you. for example
MyFormatter.toStatusString(int statusInt);
ii. compile this .java into .class. and then add the directory containing .java and .class into iReport classpath.
do this by “Option->Classpath->add folder”.
for example adding “project\build\classes” and “project\src\package\”
iii. also add the package containing that class by “Edit->Import Report Directives->New Import”
example “my.package” where MyFormatter is in my.package.MyFormatter
iv. define an expression “MyFormatter.toStatusString($F{state})”
v. compile and save the report. If you Execute (with active connection), you may get a ClassDefNotFoundException.
vi. add “import my.package.MyFormatter” into the class where you generate the JasperPrint object.
After these steps, I finally can generate a report with ClassDefNotFoundException.
God Bless.
Doing driven mode Selenium test with Java
Download Selenium Remote Control, unpack it.
Inside there is a Selenium server, and many client driver for different language.
Start the server by running java -jar selenium-server.jar. The default port is 4444.
Then open a java project in netbeans, include the client driver for java in your project, selenium-java-client-driver.jar .
Create DefaultSelenium object, this object will communicate with the server to run tests and do different tasks.
The constructor of DefaultSelenium need four parameters: hostname, port, browser string, url.
Browser string define what browser you use, please reference to the javadoc.
Here is a sample: new DefaultSelenium("localhost",4444,"*iexplore","http://www.google.com");
Run start() method to begin, stop() to close browser.
You may then integrate it with JUnit or TestNG to do data-driven tests.
According to their tutorial, TestNG should be easier.
Develop Java GUI Application with Netbeans
some reference for getting start