sreerambabu.palaniswamy Posted April 25, 2016 Share Posted April 25, 2016 HiI'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 JavaJAVA 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.]2.Add the textfield expression asFollowing Error occurs, when preview the Jasper OutputPlease advise Thanks Sreeram Link to comment Share on other sites More sharing options...
ghudson_1 Posted April 28, 2016 Share Posted April 28, 2016 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 More sharing options...
sreerambabu.palaniswamy Posted May 5, 2016 Author Share Posted May 5, 2016 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 Link to comment Share on other sites More sharing options...
krishnaaudumula Posted August 30, 2017 Share Posted August 30, 2017 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now