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

0

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

..my brain is blocked :(

 

JasperXML:

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

<textField>
  <reportElement x="429" y="49" width="100" height="18" uuid="1568d847-41de-47ee-bb6a-7ad71f523c9d"/>
  <textElement textAlignment="Left" verticalAlignment="Middle">
      <font size="12"/>
  </textElement>
      <textFieldExpression><![CDATA[$V{jasEmployee}]]></textFieldExpression>
</textField>

Java:

@Override

/*
 * Author: GZE
 */

public void buttonClick(ClickEvent event) {
// This flag controll the print-service ___ for testing it is false,...so 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();
   pAttribs.add(Sides.DUPLEX);
 
 PrintService[] printerSearchResult = PrintServiceLookup.lookupPrintServices(flavor, pAttribs);
-----------------------------

 

der.milchjieper's picture
Joined: Jan 24 2019 - 2:15am
Last seen: 2 months 4 days ago

1 Answer:

0

SOLVED ....the easy way

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

 

THX

der.milchjieper's picture
Joined: Jan 24 2019 - 2:15am
Last seen: 2 months 4 days ago
Feedback
randomness