Scriptlet - JasperStudio 5.6.1

0

Hi

I'm having issues running the scriptlet in Jasperstudio 5.6.1. I'm trying to adjust the width of the text field in the Jaspersoft using Java

JAVA Code:

 

package srTextWidth;
import java.util.Collection;import java.util.Iterator;
import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JRField;import net.sf.jasperreports.engine.JRGroup;import net.sf.jasperreports.engine.JRBand;import net.sf.jasperreports.engine.JRElement;import net.sf.jasperreports.engine.design.JRDesignExpression;import net.sf.jasperreports.engine.design.JasperDesign;import net.sf.jasperreports.engine.xml.JRXmlLoader;import net.sf.jasperreports.engine.JRDefaultScriptlet;import net.sf.jasperreports.engine.JRScriptletException;import net.sf.jasperreports.engine.design.JRDesignBand;import net.sf.jasperreports.engine.design.JRDesignSection;import net.sf.jasperreports.engine.design.JRDesignElement;
public class TestTextWidth extends JRDefaultScriptlet{  public static void main(String args[]) {        // Empty main method      try {     TestTextWidth.width();    } catch (JRException e) {     // TODO Auto-generated catch block     e.printStackTrace();    } }
public static int width() throws JRException  {
 
        JasperDesign design = JRXmlLoader.load("C:\\Sreeram\\Docs\\Jaspersoft\\Design Files\\Report_designs_Clarity Team\\MyReports\\Chart_JavaText.jrxml");        JRField[] fields = design.getFields();
        System.out.println(fields);
        for (int counter = 0; counter < fields.length; counter++) {            System.out.println(fields[counter].getName());
        }
        String elementKey = "null";        int newWidth = 200;        JRDesignBand baseBand = (JRDesignBand) design.getSummary();        JRDesignBand band = (JRDesignBand) baseBand.clone();        JRElement[] elements = band.getElements();        System.out.println(elements);        for (int counter = 0; counter < elements.length; counter++) {
            System.out.println(elements[counter].getWidth());            System.out.println(elements[counter].getHeight());            System.out.println(elements[counter].getX());            System.out.println(elements[counter].getKey());
            JRDesignElement element = (JRDesignElement) elements[counter];           //System.out.println(elementKey);           //if (elementKey.equals(element.getKey())) {             //System.out.println(elementKey);             element.setWidth(newWidth);                                              //System.out.println(element.getWidth());                                           //}        }        System.out.println(newWidth);        return newWidth;
 
        /*        String elementKey = ..key of element to modify..;        int newWidth = ..new element width..;        for (int i = 0; i < elements.length; i++)        {         JRDesignElement element = (JRDesignElement) elements[i];         if (elementKey.equals(element.getKey()))         {          element.setWidth(newWidth);         }        }</td></tr></tbody></table>
        */
    }

JRXML Code:

<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 5.6.1.final using JasperReports Library version 5.6.1  --><!-- 2016-04-25T14:42:38 --><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Chart_Main" columnCount="2" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="410" leftMargin="11" rightMargin="11" topMargin="11" bottomMargin="11" uuid="7cdf5358-037d-44d9-9ad1-f9cba97e4ec4"> <property name="com.jaspersoft.studio.unit." value="inch"/> <property name="com.jaspersoft.studio.unit.pageHeight" value="inch"/> <property name="com.jaspersoft.studio.unit.pageWidth" value="inch"/> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="UAT DB conn"/> <scriptlet name="TestTW" class="srTextWidth.TestTextWidth"/> <parameter name="param_invID" class="java.lang.String"/> <queryString language="SQL">  <![CDATA[SELECTINV.ID INVID,INV.CODE INVCODE,INV.NAME INVNAMEFROMINV_INVESTMENTS INV where INV.ID = $P{param_invID}]]> </queryString> <field name="INVID" class="java.math.BigDecimal"/> <field name="INVCODE" class="java.lang.String"/> <field name="INVNAME" class="java.lang.String"/> <background>  <band splitType="Stretch"/> </background> <summary>  <band height="211">   <textField>    <reportElement mode="Opaque" x="90" y="90" width="100" height="30" backcolor="#FF0512" uuid="a5330dcd-e401-4f96-b7a4-f71f1682f587"/>    <textFieldExpression><![CDATA[$P{TestTW_SCRIPTLET}]]></textFieldExpression>   </textField>  </band> </summary></jasperReport>

The Scriptlet are created as follows:

1.Create the Scriptlet using the Class.]

2.Add the textfield expression as

Following Error occurs, when preview the Jasper Output

Please advise

Thanks

Sreeram

sreerambabu.palaniswamy's picture
Joined: Jun 11 2015 - 9:25pm
Last seen: 1 year 1 month ago

what is the expression of the textfield you are trying to use?   Based on your screenshots, it looks almost like the expression is just the following... like no method of the scriptlet is being called:

<textFieldExpression><![CDATA[$P{TestTW_Scriptlet}]]></textFieldExpression>  

 

 

ghudson_1 - 3 years 7 months ago

Hi,

Even when I add the method, I get the similar error. Now I tried to modify the jxml by changing the width of the rectangle. It works when I compile the java program but How do I trigger the java program to make changes to jrxml

 

Thanks

 

Sreeram

sreerambabu.palaniswamy - 3 years 7 months ago

Hi Sreeram ,

the Problem is After creating Scriptlet "TestTW" and It is mandatory to give fully class path . And the Scriptlets are used by Java code JAR File Developed in Eclipse . Add JAR file to the Jaspersoft Studio File and Add to BuildPath. It is Beter to follow below mentioned PDF prepared by me step by step process.

krishnaaudumula - 2 years 3 months ago

0 Answers:

No answers yet
Feedback
randomness