therrick_1 Posted August 21, 2015 Share Posted August 21, 2015 I want to print the file location of where it's stored on hard disk in the footer of each page. This java code prints the directory location, but how do I incorporate this into Jaspersoft Studio 6.1 to get to print in page footer?:import java.io.File;File currentDir = new File("").getAbsoluteFile();System.out.println(currentDir.toString()); Link to comment Share on other sites More sharing options...
anbalagan.marimuthu Posted August 21, 2015 Share Posted August 21, 2015 Pass the path value to jasper report via hashmap & add field in jasper report with name as path & drag tha field to footer band. java code String filePath= currentDir.getAbsolutePath(); Map parameters=new HashMap();parameters.put("path",filePath); JasperFillManager.fillReport(jasperReport, parameters, new JREmptyDataSource()); jrxml <pageFooter> <band height="50"> <textField> <reportElement x="222" y="13" width="100" height="20"/> <textElement/> <textFieldExpression class="java.lang.String"><![CDATA[$F{path}]]></textFieldExpression> </textField> </band> </pageFooter> Link to comment Share on other sites More sharing options...
anbalagan.marimuthu Posted August 21, 2015 Share Posted August 21, 2015 Link to comment Share on other sites More sharing options...
therrick_1 Posted August 21, 2015 Author Share Posted August 21, 2015 Thanks for the quick reply! Where does the java code go? I expect it gets compiled into a .class file, right? Then what, do I put the .class file in the Jaspersoft Project's > Java Build Path > bin folder? And how does the Report instantiate the .class file? Does it call a java Constructor or a static method?I've seen videos for how to create Jasper Reports by using java code as the driver, but not how to get data using java code with Jasper Report as the driver. Link to comment Share on other sites More sharing options...
hozawa Posted August 22, 2015 Share Posted August 22, 2015 Create a Scriplet to hold your Java code. There's a sample in the page below:http://jasperreports.sourceforge.net/sample.reference/scriptlet/ Link to comment Share on other sites More sharing options...
therrick_1 Posted August 24, 2015 Author Share Posted August 24, 2015 Still not able to get it to work. Set it up like anbalagan said, but not working. Tried various settings of the "path" Field, but get various errors like: Unknown Column name path in result set. GetFileLoc (wrong name: com/jasper1/GetFileLoc com.jasper1.GetFileLoc cannot be resolved to a type I guess I'll try the Scriptlet approach. Java code is: package com.jasper1; import java.io.File; import java.util.HashMap; import java.util.Map; import net.sf.jasperreports.engine.JREmptyDataSource; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JasperFillManager; public class GetFileLoc { public static Map getLoc(){ File currentDir = new File(""); String filePath = currentDir.getAbsolutePath(); Map parameters=new HashMap(); parameters.put("path",filePath); String jsFileName = "C:\Users\user1\JaspersoftWorkspace\JSSJava\JSSJava1.jrxml"; try { JasperFillManager.fillReport(jsFileName, parameters, new JREmptyDataSource()); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } //String loc = currentDir.toString(); return parameters; } public static void mcomain(String[] args){ // String loc = GetFileLoc.getLoc(); // System.out.println(loc); } }// close class Link to comment Share on other sites More sharing options...
therrick_1 Posted August 24, 2015 Author Share Posted August 24, 2015 Still not able to get it to work. Set it up like anbalagan said, but not working. Tried various settings of the "path" Field, but get various errors like: Unknown Column name path in result set. GetFileLoc (wrong name: com/jasper1/GetFileLoc com.jasper1.GetFileLoc cannot be resolved to a type I guess I'll try the Scriptlet approach. Created jar file and put in Jaspersoft Build path. Java code is: package com.jasper1; import java.io.File; import java.util.HashMap; import java.util.Map; import net.sf.jasperreports.engine.JREmptyDataSource; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JasperFillManager; public class GetFileLoc { public static Map getLoc(){ File currentDir = new File(""); String filePath = currentDir.getAbsolutePath(); Map parameters=new HashMap(); parameters.put("path",filePath); String jsFileName = "C:\Users\user1\JaspersoftWorkspace\JSSJava\JSSJava1.jrxml"; try { JasperFillManager.fillReport(jsFileName, parameters, new JREmptyDataSource()); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } //String loc = currentDir.toString(); return parameters; } public static void mcomain(String[] args){ // String loc = GetFileLoc.getLoc(); // System.out.println(loc); } }// close class Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now