Jump to content
We've recently updated our Privacy Statement, available here ×

Scriptlet - JasperStudio 5.6.1


Recommended Posts

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:SreeramDocsJaspersoftDesign FilesReport_designs_Clarity TeamMyReportsChart_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>        */    }[/code]

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>[/code]

The Scriptlet are created as follows:

1.Create the Scriptlet using the Class.greenshot_2016-04-25_14-35-39.png.91671ea2ec6a9646ee72e125891fce8b.png]

2.Add the textfield expression asgreenshot_2016-04-25_14-39-02.png.56f4ec4a1435e77c8e6aabb3bdaf8456.png

Following Error occurs, when preview the Jasper Outputgreenshot_2016-04-25_14-41-04.png.0e0ebd949bf9cfb639afa3d330c7fed2.png

Please advise

 

Thanks

 

Sreeram

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

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>  

 

 

Link to comment
Share on other sites

  • 1 year later...

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.

Link to comment
Share on other sites

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