Jump to content
Changes to the Jaspersoft community edition download ×

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


der.milchjieper

Recommended Posts

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

 

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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