SOLVED - How to hand over a Java String Value from HashMap<String,Object> to Jasper $V myVariable

Hi all,

i'm a softwaredevelopment student and  new to JasperReport(JasperStudio 6.6), and i fail to hand over a Java String to a Jasper Variable. I can do this with SQL-Queries but i need

to hand over a simple String Value from my HashMap Can you people teach me quick, please? …with a CheatSheet (lineofCode) to pass the Value from HashMap to my $V jasEmployee? …

I need help with the Jasper XML <defaultValue  .... brain is blocked :(



<variable name="jasEmployee" class="java.lang.String">
  <initialValueExpression><![CDATA["John Doe"]]></initialValueExpression>

  <reportElement x="429" y="49" width="100" height="18" uuid="1568d847-41de-47ee-bb6a-7ad71f523c9d"/>
  <textElement textAlignment="Left" verticalAlignment="Middle">
      <font size="12"/>



 * Author: GZE

public void buttonClick(ClickEvent event) {
// This flag controll the print-service ___ for testing it is false, no paper will be wasted
 boolean printThePDF = false;
   try {
* Careful, the JRXML has to be manually update if you change
    * the Template Directory

  String templateDirectory = "D:/Apps/eLog/docs/JasperReport/Order/";
  String templateFileName = "eLog.jrxml";
  String absoluteTemplateFileName = templateDirectory + templateFileName;
  String outputPath = "D:/temp/";
  String outputFilename = oderID + "_" + "Customer-" + customerID + "_" + System.currentTimeMillis() + "_Order.pdf";
  String outputStream = outputPath + outputFilename;

  HashMap<String, Object> parameterMap = new HashMap<String, Object>();
 * KEY = exact Name of the JasperReport Variable / Parameter
   * VALUE = Java variables
      // ____________________KEY______ VALUE___
   parameterMap.put("jasEmployee", this.getEmployeeName().toString());
  parameterMap.put("jasPackstation", comboPackstation.getValue().toString());
   parameterMap.put("jasCarrier", carrier);  
parameterMap.put("jasOrderID", orderID);
   parameterMap.put("jasCustomerID", customerID);
   * JasperReport
Connection connection = new SystemDatabaseConnection().getMwsDBconnection().getDatabaseConnection();
   JasperReport jrCM = JasperCompileManager.compileReport(absoluteTemplateFileName);
JasperPrint jasperPrint = JasperFillManager.fillReport(jrCM, parameterMap, connection);
 JasperExportManager.exportReportToPdfFile(jasperPrint, outputStream);
 * PrinterSection
   DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PAGEABLE;
   PrintRequestAttributeSet pAttribs = new HashPrintRequestAttributeSet();
 PrintService[] printerSearchResult = PrintServiceLookup.lookupPrintServices(flavor, pAttribs);


der.milchjieper's picture
Joined: Jan 24 2019 - 2:15am
Last seen: 4 years 1 month ago

1 Answer:

SOLVED ....the easy way

Variables are not Parameters, ...the HashMap is a "Parameter"-Map Variable will be filled automaticly by this Map, ...i deleted all my Variables and replaced all with same named Parameters, ...for my's the best and simplest solution. :)



der.milchjieper's picture
Joined: Jan 24 2019 - 2:15am
Last seen: 4 years 1 month ago