2009-08-06: Release of 0.6.0 är släppt 2009-05-22: Utgåva av 0.5.0 släpps 2009-03-16: Utgivning av 0.5.0 beta. 2008-06-20: Release of 0.4.1, återlansering av Wiki-webbplatsen och inkludering av forumet som inbäddade sidor: User Forum och Developers Forum. Njut av 2008-05-04 Appendium Ltd och LavaBlast är glada att tillkännage release av version 0.4.0 av StatSVN. Mer detaljer om denna blogg och changelog. 2007-03-10 Nyheter. Som en del av utgåva 0.3.1 har vi lanserat en serie demo för några kända projekt: Subversion, Ant, Log4J, Spring Rich Client, Hibernate 3, Joda Time, Ruby, Groovy, Grails och Felix till att börja med. Fortsätt, erkänna det, du ville alltid veta vem gjorde vad och när på de projekten. Varning. om du inte använder ett engelskt språk, ange LANG-miljövariabeln till enUS när du kör programmet tills vi löser några i18n-problem med StatSVN (samtalet till svn diff returnerar en lokal sträng som kan leda till att vissa resultat inte cachas, resultaten är korrekta men StatSVN kommer att fråga dem igen nästa gång). 2007-02-07: Vill du hjälpa Var att överväga att ersätta våra kommandoradinokationer med samtal till SVNKit (tidigare JavaSVN). Vill du skriva prototypimplementeringen och se hur bra den fungerar Låt oss veta 2007-01-12: Version 0.3.0 finns i SVN och lägger till 2 rapporter (RepoMap och LOCChurn) samt att fixa ett antal problem med att flytta filer, kataloger och radering av dessa. Mer detaljer på denna sida. 2006-11-28: Version 0.2.0 är ute och stöder nu Html och XDoc generation för att underlätta integrationen med Maven (se rapporter här). Det var också glädjande att nämna att det finns ett Maven 2-plugin med StatSVN, det finns tillgängligt på stat-scm. sourceforge. Tweet Tweet från författarna Så vad är StatSVN? Stor statistik för SVN StatSVN hämtar information från ett Subversion-arkiv och genererar olika tabeller och diagram som beskriver projektutvecklingen, t. ex. Tidslinje för kodens linjer Linjer av kod för varje utvecklare Aktivitet per klocktid Författare Aktivitet Författaraktivitet per Modul Författare Senaste inlägg med länkar till ViewVc-statistik per katalog Filantal Genomsnittlig filstorlek Största filer Filer med de flesta ändringar Katalog Storlekar Repository Etiketter Antal LOC per version. Repository tree med filantal och kodnummer LOC och avbryt utvecklingen av LOC och mängden förändring per dag Repo Karta den dynamiska hierarkiska visningen av din repo de senaste 30 dagarna Den nuvarande versionen av StatSVN genererar en statisk serie HTML-dokument som innehåller tabeller och diagrambilder. StatSVN är öppen källkodsprogram, som släpps ut enligt villkoren i LGPL, baserat på StatCVS. StatSVN använder JFreeChart för att generera diagram. Var finns manualen Handboken är tillgänglig online som en Wiki och den är så aktuell och omfattande som du vill att den ska vara. Snabbt exempel på Maven 1 Innan du kör maven site (eller helt enkelt maven xdoc) kan du skapa XDOC-filer genom att springa: (glöm inte - v). Detta exempel kommer att generera xdoc i katalog sitestatsvn, tagg 0.2.0, 0.1.3, 0.1.2, 0.0.9, utesluta qalab. xml och andra. Därefter skulle XDOC plockas upp av maven site eller maven xdoc. Observera att för att använda taggarna måste du använda en loggfil inte på bagageplanen, men precis ovanför, för att inkludera taggkatalogen. För närvarande arbetar StatSVN bara med tagskatalog. Snabbt exempel på ny dump Det finns en ny dumpanläggning (glöm inte - v). Detta kommer att generera en stor mängd utdata, men i slutet, om det visar OK för allt är det troligt att StatSVN korrekt förstod ditt förråd: JasperReports - Snabbguide JasperReports - Komma igång JasperReports - Miljöuppsättning JasperReports - Livscykel JasperReports - Design JasperReports - Kompilera rapportdesign JasperReports - Fyllningsrapporter Jasperrapport - Visa amp Skriv ut Rapporter JasperReports - Exportera Rapporter Rapporter Parametrar Om de är inställda på java. lang. Boolean. TRUE kommer rapporten att genereras på en lång sida och sidbrytning kommer inte att uppstå. Låt oss vidarebefordra ReportTitle och Author till rapporten (genererad av JasperReportFill. java). Reviderad fil C: toolsjasperreports-5.0.1testsrccomtutorialspointJasperReportFill. java är som följer minus Innehållet i POJO-filen C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBean. java är som under minus Innehållet i filen C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBeanList. java är som ges nedan minus Vi lägger till parametrarna lt ReportTitle gt och lt Författare gt till vår befintliga rapportmall (Kapitelrapporter). Rapporttiteln och författaren kommer att visas i början av rapporten. Den reviderade rapportmallen (jasperreporttemplate. jrxml) är som följer. Spara det till C: toolsjasperreports-5.0.1test katalog minus Report Generation Vi kommer att kompilera och exekvera ovanstående fil med vår vanliga ANT-byggprocess. Innehållet i filen build. xml (sparat under katalog C: toolsjasperreports-5.0.1test) är som nedan. Importfilen - baseBuild. xml plockas från kapitlet Miljöinställningar och ska placeras i samma katalog som build. xml. Därefter öppnas kommandoradsfönstret och går till katalogen där build. xml är placerad. Slutligen kör kommandot ant - Dmain-classcom. tutorialspoint. JasperReportFill (viewFullReport är standardmålet) enligt följande minus Som ett resultat av ovanstående samling öppnas ett JasperViewer-fönster som visas i följande skärm minus Här ser vi att ReportTitle lista över kontakter och författare förberedd av Manisha visas i början av rapporten. Rapportera datakällor Datakällor är strukturerad databehållare. Samtidigt som rapporten genereras, erhåller JasperReports-motorn data från datakällorna. Data kan erhållas från databaser, XML-filer, arrayer av objekt och samling av objekt. Vi såg i kapitlet Fyllningsrapporter. Metoden fillReportXXX () förväntar sig att ta emot en datakälla för rapporten, som måste fylla i form av net. sf. jasperreports. engine. JRDataSource-objekt eller en java. sql. Connection (när rapportdata finns i en relationell databas). JRDataSource-gränssnittet har bara två metoder, som bör implementeras minus offentliga booleanska nästa () slår JRException Vid rapportens fyllningstid kallas den här metoden för datakällaobjektet av rapporteringsmotorn när det är iterering via data. public Object getFieldValue (JRField jrField) kastar JRException Denna metod ger värdet för varje rapportfält i den aktuella datakällans post. Det enda sättet att hämta data från datakällan är att använda rapportfälten. Det finns flera standardimplementeringar av gränssnittet för JRDataSource, beroende på hur posten i datakällan förvärvas. Datakällans genomförande Tabellen nedan ger en sammanfattning av datakällorna och deras implementeringsklasser minus JDBC-datakällor klass JRResultSetDataSource craps ett java. sql. ResultSet-objekt. Det här är de vanligaste datakällans implementeringar när rapportdata extraheras från en relationsdatabas. Om en java. sql. Connection skickas till motorn i stället kör den först den relaterade frågan och lagrar det returnerade java. sql. ResultSet-objektet i en JRResultSetDataSource-instans. JavaBean-datakällarklasser JRBeanArrayDataSource och JRBeanCollectionDataSource representerar implementeringar som kan inveckla arrayer och samlingar av JavaBean-objekt. Varje objekt inuti matrisen eller samlingen kommer att ses som en post i denna typ av datakälla. Kartläggningen mellan en viss JavaBean-egenskap och motsvarande rapportfält görs genom att namnge konventioner. Namnet på rapportfältet måste vara detsamma som namnet på JavaBean-egenskapen enligt JavaBeans-specifikationerna. I alla exemplen på denna handledning har vi använt JRBeanCollectionDataSource. Kartbaserade datakällor Implementeringsklasserna JRMapArrayDataSource och JRMapCollectionDataSource är användbara om moderprogrammet redan lagrar rapporteringsdata som är tillgängliga i minnet som java. util. Map-objekt. Varje kartobjekt i det inslagna arrayet eller samlingen betraktas som en virtuell post i datakällan, och värdet av varje rapportfält extraheras från kartan med hjälp av rapportfältet namngivet som nyckeln. TableModel datakällor I många applikationer på klientsidan visas data i tabellformat. Ett vanligt krav i många applikationer är att tillåta användaren att skriva ut detta tabellformat som en rapport. Implementeringsklass JRTableModelDataSource gör uppgiften att generera rapporter från tabellformat trivialt för Swing-applikationer. Denna klass wraps ett javax. swing. table. TableModel objekt. Kolumner i det inslagna TableModel-objektet kan nås antingen med deras namn eller med sina 0-baserade index. XML-datakällor Klass JRXmlDataSource är en implementering av datakällor baserat på DOM, som använder XPath-uttryck för att välja data från XML-dokumentet. Rekord i XML-datakällan representeras av nodelement som valts genom XPath-uttrycket. Fältvärden hämtas från varje post med XPath-uttrycket som tillhandahålls av fältbeskrivningen (ltfieldDescriptiongt-element i JRXML). XPath är ett språk som används för att navigera genom en XML-dokument attribut och element. Mer information om XPath finns på w3.orgTRxpath. CSV-datakällor JRCsvDataSource representerar ett genomförande för datakällor, som hämtar sina data från strukturerade textfiler som vanligtvis CSV. Fältvärden hämtas med deras kolumnindex. XLS-datakällor JRXlsDataSource representerar ett genomförande för datakällor, som hämtar sina data från Excel-dokument. Report-field mapping för denna implementering av datakälla bygger också på fältets kolumnindex. Tomma datakällor Klassen JREmptyDataSource. simulerar en datakälla med ett visst antal virtuella tomma poster inuti. Det används av UI-verktygen för att erbjuda grundläggande rapportförhandsgranskningsfunktioner, eller i speciella rapportmallar, eller för testning och felsökningsändamål. Återspegliga datakällor Net. sf. jasperreports. engine. JRRewindableDataSource utökar det grundläggande JRDataSource-gränssnittet. Det adderar bara en metod, kallad moveFirst (), till gränssnittet. Metoden är avsedd att flytta markören till det första elementet i datakällan. Återlöpbara datakällor är användbara när du arbetar med delrapporter placerade i ett band som inte får delas på grund av isSplitAllowedfalse-inställningen och det finns inte tillräckligt med plats på den aktuella sidan för delrapporten som ska göras. Alla ovanstående datakällans implementeringar är återspolbara utom för JRResultSetDataSource. eftersom det inte stöder att flytta registreringspekaren tillbaka. Detta innebär endast ett problem om denna datakälla används manuellt för att pakka in en java. sql. ResultSet innan den skickas till delrapporten. Det finns inga problem om SQL-frågan finns i delrapportmallen, eftersom motorn kommer att exekvera den igen när omstart av delrapporten på nästa sida startas. Datakällaleverantörer JasperReports-biblioteket har ett gränssnitt net. sf. jasperreports. engine. JRDataSourceProvider. Detta hjälper till att skapa och bortskaffa datakällaobjekt. När du skapar en rapportmall med hjälp av GUI-verktyg behövs ett specialverktyg för anpassning av rapportens datakälla. JRDataSourceProvider är det vanliga sättet att ansluta anpassade datakällor till ett designverktyg. En anpassad implementering av detta gränssnitt bör genomföra följande metoder som tillåter att skapa och bortskaffa datakällaobjekt och även metoder för att lista de tillgängliga rapportfälten i datakällan om möjligt minus rapportfält Rapportfält är element, som representerar kartläggning av data mellan datakälla och rapportera mall. Fält kan kombineras i rapportuttryck för att erhålla önskad produktion. En rapportmall kan innehålla noll eller flera ltfieldgt-element. När deklarerar rapportfält ska datakällan tillhandahålla data som motsvarar alla fält som definieras i rapportmallen. Fältdeklaration Fältdeklaration görs enligt nedan Minus Namnattribut Namnattributet för ltfieldgt-elementet är obligatoriskt. Den refererar till fältet i rapportuttryck med namn. Klassattributtet Klassattributet anger klassnamnet för fältvärdena. Standardvärdet är java. lang. String. Detta kan ändras till någon klass som är tillgänglig vid körning. Oavsett typ av ett rapportfält tar motorn hand om gjutning i rapportuttryck där F-token används, vilket gör att manuell omkastning inte behövs. Fält Beskrivning DetItfieldDesciptiongt-elementet är ett valfritt element. Det här är mycket användbart när du implementerar en anpassad datakälla. Till exempel kan vi lagra en nyckel eller någon information, genom vilken vi kan hämta värdet på fältet från den anpassade datakällan vid körning. Genom att använda ltfieldDesciptiongt-elementet istället för fältnamnet kan du enkelt övervinna begränsningar av fältnamnskonventioner när man hämtar fältvärdena från datakällan. Följande är en del kod från vår befintliga JRXML-fil (Kapitelrapport Designs). Här kan vi se användningen av namn. klass . och fieldDescription elements. Sortera fält Vid de tidpunkter då datasortering krävs och datakällans implementering inte stöder den (t. ex. CSV-datakälla), stöder JasperReports in-memory-fältbaserad datakälla sortering. Sorteringen kan göras med hjälp av ett eller flera ltsortFieldgt-element i rapportmallen. Om minst ett sorteringsfält anges, under rapportfyllningsprocessen, skickas datakällan till en JRSortableDataSource-instans. Detta hämtar i sin tur alla poster från datakällan, utför i minnesort enligt angivna fält och ersätter den ursprungliga datakällan. Sorteringsfältnamnet ska vara identiskt med rapportfältnamnet. Fält som används för sortering ska ha typer som implementerar java. utilparable. Sortering av naturliga sorteringar utförs för alla fält utom de av typen java. lang. String (för strängtyp används kollatorn som motsvarar rapportfyllningslandet). När flera sorteringsfält anges, sorteras sorteringen med fälten som sorteringsnycklar i den ordning de visas i rapportmallen. Följande exempel visar sorteringsfunktionen. Sorterat rapportexempel Vi lägger till elementet lt sortField gt i vår befintliga rapportmall (Kapitelrapport-mönster). Låt sorteringsfält landa i fallande ordning. Den reviderade rapportmallen (jasperreporttemplate. jrxml) är som följer. Spara den till C: toolsjasperreports-5.0.1test-katalogen minus Java-koderna för rapportfyllning förblir oförändrade. Innehållet i filen C: toolsjasperreports-5.0.1testsrccomtutorialspointJasperReportFill. java är som angivet nedan minus Innehållet i POJO-filen C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBean. java är som anges nedan minus Innehållet i filen C: toolsjasperreports-5.0. 1testsrccomtutorialspointDataBeanList. java är som anges nedan minus Rapportgenerering Vi kommer att kompilera och exekvera ovanstående fil med vår vanliga ANT-byggprocess. Innehållet i filen build. xml (sparade under katalog C: toolsjasperreports-5.0.1test) är som anges nedan. Importfilen - baseBuild. xml plockas från kapitlet Miljöinställningar och ska placeras i samma katalog som build. xml. Därefter öppnas kommandoradsfönstret och går till katalogen där build. xml är placerad. Slutligen kör kommandot ant - Dmain-classcom. tutorialspoint. JasperReportFill (viewFullReport är standardmålet) enligt följande minus Som ett resultat av ovanstående samling öppnas ett JasperViewer-fönster som visas på skärmen nedan minus Här kan vi se det Landnamnen är ordnade i fallande ordning alfabetiskt. Report Expression Report uttryck är de kraftfulla funktionerna i JasperReports, vilket gör att vi kan visa beräknade data på en rapport. Beräknad data är den data som inte är en statisk data och är inte specifikt godkänd som en rapportparameter eller datakälla. Rapportuttryck bygger på att kombinera rapportparametrar, fält och statiska data. Java-språket används som standard för att skriva rapportuttryck. Andra skriptspråk för rapportuttryck som Groovy skriptspråk, JavaScript eller BeanShell-skript stöds av JasperReports-kompilatorer. I det här kapitlet kommer du att förklara dig minus hur det fungerar som uttrycksuttryck, förutsatt att de endast har skrivits med hjälp av Java-språket. I en JRXML-rapportmall finns det flera element som definierar uttryck som minus ltvariableExpressiongt ltinitialValueExpressiongt ltgroupExpressiongt ltprintWhenExpressiongt ltimageExpressiongt lttextFieldExpressiongt Uttrycksdeklaration I princip är alla rapportuttryck Java-uttryck som kan referera till rapportfälten, rapportera variabler och rapportera parametrar. Fältreferens i uttryck För att använda en rapportfältreferens i ett uttryck måste fältets namn anges mellan F - och teckensekvenser, vilket visas nedan Minus Följande är ett kodnummer från vår befintliga JRXML-fil (kapitel Rapportdesign) minus Variabel Referens i uttryck För att hänvisa till en variabel i ett uttryck måste vi ange variabelns namn mellan V och som visas i exemplet nedan, minus Parameterreferens i uttryck För att hänvisa till en parameter i ett uttryck ska parameterns namn anges mellan P och som visas i exemplet nedan minus Följande är en kod kod från vår befintliga JRXML-fil, som visar referensen av parameter i ett uttryck. (JRXML från kapitel Rapport Designs) minus Som du har sett ovan är parametrar, fält och variabla referenser i själva verket riktiga Java-objekt. Att veta sin klass från parametern, fältet eller den variabla deklarationen som gjorts i rapportmallen kan även kalla metoder på dessa objektreferenser i uttrycken. Följande exempel visar minus hur man extraherar och visar den första bokstaven från java. lang. String rapportfältet Namn minus Resource Bundle Reference in Expression För att referera till en resurs i ett uttryck ska nyckeln sätts mellan R och som visas i exemplet under minus Baserat på den runtime-levererade locale - och report. title-tangenten laddas resursbuntet som är associerat med rapportmallen. Därför visas titeln på rapporten genom att extrahera strängvärdet från resursbuntet. Mer om internationalisering finns i kapitlet Internationalisering. Calculator Calculator är en enhet i JasperReports, som utvärderar uttryck och ökar variabler eller dataset vid rapportfyllningstiden. Under sammanställningsprocessen produceras informationen och lagras i kompilatorns sammanställningsrapport. Denna information används under rapportfyllningstiden för att bygga en instans av klassen net. sf. jasperreports. engine. fill. JRCalculator. Java-källfilen genereras och sammanställs av Java-baserade rapportkompilatorer på flyg. Den här genererade klassen är en underklass av JRCalculator, och bytekoden som produceras genom att sammanställa den lagras inuti JasperReport-objektet. Denna bytcode laddas på rapportfyllningstiden och den resulterande klassen är instansierad för att erhålla det beräkningsobjekt som behövs för expressionsutvärdering. Villkorliga uttryck JasperReports stöder inte if-else uttalanden när man definierar variabla uttryck. Istället kan du använda de ternära operatörerna. . . Denna operatör kan nästas inuti ett Java-uttryck för att erhålla önskad utgång baserad på flera villkor. Exempel på villkorlig uttryck i rapporten Låter ändra befintlig rapportmall (Kapitelrapporter) och lägga till ett villkorligt uttryck för fältlandet. Den reviderade rapportmallen (jasperreporttemplate. jrxml) är som följer. Spara det till C: toolsjasperreports-5.0.1test katalog minus Java-koderna för rapportfyllning är enligt följande. Innehållet i filen C: toolsjasperreports-5.0.1testsrccomtutorialspointJasperReportFill. java är som minus Innehållet i POJO-filen C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBean. java är som minus Vi lägger till en ny post med landfältet som tomt i vår Java-böna Lista. Innehållet i filen C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBeanList. java är som minus Report Generation Vi kommer att kompilera och exekvera ovanstående fil med vår vanliga ANT-byggprocess. Innehållet i filen build. xml (sparat under katalog C: toolsjasperreports-5.0.1test) ges nedan. Importfilen - baseBuild. xml plockas från kapitel Miljöinställningen och ska placeras i samma katalog som build. xml. Därefter öppnas kommandoradsfönstret och går till katalogen där build. xml är placerad. Slutligen kör kommandot ant - Dmain-klass com. tutorialspoint. JasperReportFill (viewFullReport är standardmålet) som minus Som ett resultat av ovanstående kompilering öppnas ett JasperViewer-fönster som visas på skärmen nedan minus Här kan vi se, För den sista posten hade vi inte skickat några data för fältlandet, inget land skrivs ut. Rapportvariabler Rapportvariabler är speciella objekt som byggts ovanpå rapportuttrycket. Rapportvariabler förenklar följande uppgifter minus Rapportuttryck, som används kraftigt i hela rapportmallen. Dessa uttryck kan deklareras en gång genom att använda rapportvariablerna. Rapportvariabler kan utföra olika beräkningar baserade på motsvarande uttrycksvärden som räkning, summa, medel, lägsta, högsta, varians etc. Om variabler definieras i en rapportdesign kan dessa refereras av nya variabler i uttrycken. Följaktligen är ordningen vari variablerna deklareras i en rapportdesign viktig. Variabeldeklaration En variabel deklaration är som följer minus Som ovan sett innehåller ltvariablegt-elementet antal attribut. Dessa attribut sammanfattas under minus The Name Attribut som liknar parametrar och fält. Namnet attributet av ltvariablegt element är obligatorisk. Det gör det möjligt att hänvisa variabeln med det deklarerade namnet i rapportuttryck. Klassattributet Klassattributet är också obligatoriskt som anger klassnamnet för variabelvärdena. Standardvärdet är java. lang. String. Detta kan ändras till vilken som helst klass som är tillgänglig i klassväg, både vid rapportens sammanställningstid och rapportfyllningstiden. Motorn tar hand om typgjutning i rapportuttryck som V-token används, varför manuell manuell gjutning inte krävs. Beräkning Detta attribut bestämmer minus vilken beräkning som ska utföras på variabeln när man fyller i rapporten. Följande avsnitt beskriver alla möjliga värden för beräkningsattributet för det ltvariablegt-elementet. Genomsnittlig minus Det variabla värdet är medelvärdet av varje icke-nullvärde för variabeluttrycket. Gäller bara för numeriska variabler. Räkna minus Det variabla värdet är räkningen av icke-null-instanser av variabeluttrycket. Första minus Det variabla värdet är värdet av den första instansen av variabeluttrycket. Efterföljande värden ignoreras. Högsta minus Det variabla värdet är det högsta värdet för variabeluttrycket. Lägsta minus Det rörliga värdet är det lägsta värdet för variabeluttrycket i rapporten. Ingenting minus Inga beräkningar utförs på variabeln. Standardavvikelser minus Det variabla värdet är standardavvikelsen för alla icke-nullvärden som matchar rapportuttrycket. Gäller bara för numeriska variabler. Summa minus Det rörliga värdet är summan av alla icke-nullvärden som returneras av rapportuttrycket. System minus Det rörliga värdet är en anpassad beräkning (beräkning av värdet för den variabeln själv med hjälp av scriptlets funktionalitet i JasperReports). Varians minus Det variabla värdet är variansen av alla icke-nullvärden som returneras genom utvärdering av rapportvariablerna. Incrementer FactoryClass Detta attribut bestämmer vilken klass som används för att beräkna värdet på variabeln när den fyller aktuell post i rapporten. Standardvärdet skulle vara vilken klass som helst som implementerar net. sf. jasperreports. engine. fill. JRIncrementerFactory. Fabrikatklassen kommer att användas av motorn för att instansera inkrementerobjekt vid körning beroende på beräkningsattributet som är inställt för variabeln. IncrementType Detta bestämmer när du ska omberäkna värdet på variabeln. Detta attribut använder värden, som under minus kolumn minus Det rörliga värdet räknas om i slutet av varje kolumn. Grupp minus Det rörliga värdet räknas om när gruppen som anges av incrementGroup ändras. Ingen minus Det rörliga värdet räknas om med varje post. Sida minus Det rörliga värdet räknas om i slutet av varje sida. Rapport minus Det rörliga värdet räknas om en gång i slutet av rapporten. IncrementGroup Detta bestämmer namnet på gruppen där variabelvärdet omräknas, när incrementType är Group. Det här namnet på vilken grupp som deklareras i JRXML-rapportmallen. Detta bestämmer när värdet på en variabel återställs. Detta attribut använder värden, som under minus kolumn minus Det rörliga värdet återställs i början av varje kolumn. Grupp minus Det rörliga värdet återställs när gruppen som anges av incrementGroup ändras. Ingen minus Det rörliga värdet återställs aldrig. Sida minus Det rörliga värdet återställs i början av varje sida. Rapport minus Det rörliga värdet återställs endast en gång, i början av rapporten. ResetGroup Detta bestämmer namnet på gruppen där variabelvärdet återställs, när resetType är Group. Värdena för detta attribut skulle vara namnet på en grupp som deklarerats i JRXML-rapportmallen. Inbyggda rapportvariabler Det finns några inbyggda systemvariabler, klara att använda i uttryck, enligt följande minus variabelt namn och beskrivning Detta variablervärde är dess aktuella sidnummer. Den kan användas för att visa både det aktuella sidnumret och det totala antalet sidor med hjälp av en särskild funktion i JasperReports textfältelement, attributet evaluationTime. Namnet på den här variabeln härleds från namnet på den grupp den motsvarar, suffixad med COUNT-sekvensen. Denna variabel innehåller antalet poster i den aktuella gruppen. Låt lägga till en variabel (countNumber) till vår befintliga rapportmall (Kapitelrapporterna). Vi kommer att prefixera räkningen till varje post. Den reviderade rapportmallen (jasperreporttemplate. jrxml) är som följer. Spara den till C: toolsjasperreports-5.0.1test-katalogen minus Java-koderna för rapportfyllning förblir oförändrade. Innehållet i filen C: toolsjasperreports-5.0.1testsrccomtutorialspointJasperReportFill. java är som angivet nedan minus Innehållet i POJO-filen C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBean. java är som anges nedan minus Innehållet i filen C: toolsjasperreports-5.0. 1testsrccomtutorialspointDataBeanList. java är som ges nedan minus Report Generation Vi kommer att kompilera och exekvera ovanstående fil med vår vanliga ANT-byggprocess. Innehållet i filen build. xml (sparade under katalog C: toolsjasperreports-5.0.1test) är som anges nedan. Importfilen - baseBuild. xml plockas från kapitlet Miljöinställningar och ska placeras i samma katalog som build. xml. Därefter öppnas kommandoradsfönstret och går till katalogen där build. xml är placerad. Slutligen, kör kommandot ant - Dmain-classcom. tutorialspoint. JasperReportFill (viewFullReport är standardmålet) som minus Som ett resultat av ovanstående samling öppnas ett JasperViewer-fönster som på skärmen nedan minus Här ser vi att räkningen är prefixad för varje post. Rapporteringssektioner Vi diskuterade strukturen för en enkel rapportmall i kapitlet Komma igång. På liknande sätt strukturerar JasperReports rapportmallen i flera sektioner. Sektioner är delar av rapporten som har en angiven höjd och kan innehålla rapportobjekt som linjer, rektanglar, bilder eller textfält. Rapportmotorens iterates genom virtuella register över den medföljande rapportdatakällan vid rapportfyllningstiden. Beroende på varje sektions definierat beteende gör motorn sedan varje rapportavsnitt när det är lämpligt. Till exempel återges detaljavsnittet för varje post i datakällan. När sidbrytningar uppstår gjordes sidhuvud och sidfotfältavsnitt efter behov. I JasperReports kallas även terminologi - och rapportavsnitt som rapportband. Sektioner består av ett eller flera band. Dessa avsnitt fylls upprepade gånger på rapportgenererande tid och förbereder slutdokumentet. Huvudavsnitt En rapportmall i JasperReports har följande huvudavsnitt minus Följande tabell sammanfattar var och en av sektionerna minus Höjd i avsnittet anger höjden i pixlar för det aktuella avsnittet och är mycket viktigt i den övergripande rapportdesignen. Skriv ut när uttryck Ett booleskt uttryck som bestämmer huruvida sektionen ska skrivas ut eller inte. Split tillåtet En flagga som anger om sektionen får delas när den inte passar på den aktuella sidan. Om det är sant, kommer sektionen att överföras till nästa sida. Observera att om sektionen inte passar på nästa sida, delas sektionen oberoende av flaggvärdet. splitType kan ta följande värden minus splitTypeStretch: Splits sträckt innehåll. Om sektionen sträcker sig på den aktuella sidan (om tillgängligt utrymme är mindre än den angivna höjden) får den region som läggs till den ursprungliga höjden delas upp på nästa sida. splitTypePrevent: Förhindra splittring vid första försöket. Om sektionen inte passar på nästa sida sker splittringen normalt, eftersom bandspaltningsförhindring endast är effektiv vid det första splittningsförsöket. splitTypeImmediate: Split direkt. Bandet får delas överallt utom ovan, dess översta element. För att visa varje avsnitt kan vi skriva rapportmall (jasperreporttemplate. jrxml). Spara den här filen i katalogen C: toolsjasperreports-5.0.1test. I den här filen skulle vi visa en text i var och en av de avsnitten (vi diskuterade ovan). Innehållet i filen är som angivet nedan minus Den java-kod som ska fyllas i och generera rapporten ges nedan. Lets spara den här filen JasperReportFill. java till C: toolsjasperreports-5.0.1testsrccomtutorialspoint katalogen. Här använder vi en instans av JREmptyDataSource när du fyller i rapporter för att simulera en datakälla med en post i den, men med alla fält i den här enskilda posten är null. Report Generation Vi kommer att kompilera och exekvera ovanstående fil med vår vanliga ANT-byggprocess. Innehållet i filen build. xml (sparat under katalog C: toolsjasperreports-5.0.1test) är som nedan. Importfilen - baseBuild. xml hämtas från kapitlet Miljöinställningar och ska placeras i samma katalog som build. xml. Därefter öppnas kommandoradsfönstret och går till katalogen där build. xml är placerad. Slutligen kör kommandot ant - Dmain-classcom. tutorialspoint. JasperReportFill (viewFullReport är standardmålet) enligt följande minus Som ett resultat av ovanstående samling öppnas ett JasperViewer-fönster som på skärmen nedan minus Här kan vi se i var och en av the sections a text is printed. It is to be noted that as JRXML contains a ltlastPageFootergt element, it will be displayed in the last page of the report instead of the ltpageFootergt element being displayed. The ltcolumnHeadergt and ltcolumnFootergt elements will only be displayed on the report, if it has more than one column. Report Groups Groups in JasperReports help to organize data on report in a logical manner. A report group represents a sequence of consecutive records in the data source, which have something in common, such as the value of a certain report fields. A report group is defined by the ltgroupgt element. A report can have any number of groups. Once declared, groups can be referred throughout the report. A report group has three elements minus Group expression minus This indicates the data that must change to start a new data group. Group header section minus Helps place label at the beginning of the grouped data. Group footer section minus Helps place label at the end of the grouped data. During the iteration through the data source at report-filling time if the value of the group expression changes, a group rupture occurs and the corresponding ltgroupFootergt and ltgroupHeadergt sections are inserted in the resulting document. Report group mechanism does not perform any sorting on the data supplied by the data source. Data grouping works as expected only when the records in the data source are already ordered according to the group expressions used in the report. Group Attributes The ltgroupgt element contains attributes that allow us to control how grouped data is laid out. The attributes are summarized in table below minus Attribute and Description This is mandatory. It references the group in report expressions by name. It follows the same naming conventions that we mentioned for the report parameters, fields, and report variables. It can be used in other JRXML attributes when you want to refer a particular report group. When set to true . each data group will begin on a new column. Default value is false . When set to true . prevents the group from splitting on its first break attempt. Lets add a group ( CountryGroup ) to existing report template (Chapter Report Designs ). Occurrence of each country is counted and the count is displayed as the group footer. In the group header, the count of each record is prefixed. The revised report template (jasperreporttemplate. jrxml) is as follows. Save it to C:toolsjasperreports-5.0.1test directory minus The java codes for report filling remains unchanged. The contents of the file C:toolsjasperreports-5.0.1testsrccomtutorialspointJasperReportFill. java are as given below minus The contents of the POJO file C:toolsjasperreports-5.0.1testsrccomtutorialspointDataBean. java are as below minus The contents of the file C:toolsjasperreports-5.0.1testsrccomtutorialspointDataBeanList. java are as given below minus Report Generation We will compile and execute the above file using our regular ANT build process. The contents of the file build. xml (saved under directory C:toolsjasperreports-5.0.1test) are as below. The import file - baseBuild. xml is picked up from chapter Environment Setup and should be placed in the same directory as the build. xml. Next, lets open command line window and go to the directory where build. xml is placed. Finally, execute the command ant - Dmain-classcom. tutorialspoint. JasperReportFill (viewFullReport is the default target) as minus As a result of above compilation, a JasperViewer window opens up as in the screen below minus Here, we see that the each country is grouped and the count of occurrence of each country is displayed at the footer of each group. Report Fonts A report contains text elements and each of these can have its own font settings. These settings can be specified using the lt font gt tag available in the lttextElementgt tag. A report can define a number of fonts. Once defined, they can be used as default or base font settings for other font definitions throughout the entire report. Report Fonts A report font is a collection of font settings, declared at the report level. A report font can be reused throughout the entire report template when setting the font properties of text elements. Report fonts are now deprecated. Do not use ltreportFontgt elements declared within the document itself. Use the ltstylegt element instead. Font Attributes Table below summarizes the main attributes of the lt font gt element minus The flag that specifies whether the font should be embedded into the document itself. It defaults to false. If set to true, helps view the PDF document without any problem. Font Types In JasperReports fonts can be categorized as minus Logical Fonts minus Five font types, which have been recognized by the Java platform since version 1.0, are called logical fonts. These are minus Serif, SansSerif, Monospaced, Dialog, and DialogInput . These logical fonts are not actual font libraries that are installed anywhere on the system. They are merely font type names recognized by the Java runtime. These must be mapped to some physical font that is installed on the system. Physical Fonts minus These fonts are the actual font libraries consisting of, for example, TrueType or PostScript Type 1 fonts. The physical fonts may be Arial, Time, Helvetica, Courier, or any number of other fonts, including international fonts. Font Extensions minus The JasperReports library can make use of fonts registered on-the-fly at runtime, through its built-in support for font extensions. A list of font families can be made available to the JasperReports using font extension. These are made out of similarly looking font faces and supporting specific locales. As described in the table above we need to specify in the attribute fontName the name of a physical font, the name of a logical font, or the name of a font family from the registered JasperReports font extensions. PDF Font Name JasperReports library uses the iText library, when exporting reports to PDF(Portable Document Format). PDF files can be viewed on various platforms and will always look the same. This is partially because in this format, there is a special way of dealing with fonts. fontName attribute is of no use when exporting to PDF. Attribute pdfFontName exist where we need to specify the font settings. The iText library knows how to deal with built-in fonts and TTF files and recognizes the following built-in font names minus Courier Courier-Bold Courier-BoldOblique Courier-Oblique Helvetica Helvetica-Bold Helvetica-BoldOblique Helvetica-Oblique Symbol Times-Roman Times-Bold Times-BoldItalic Times-Italic ZapfDingbats As per iText library pre-requisite, to work with fonts, we need to specify one of the following as the font name minus A built-in font name from the above list. The name of a TTF (True Type Font) file, which it can locate on disk. The real name of the font, provided that the TTF file containing the font has been previously registered with iText or that an alias was defined when the font was registered. Based on the above pre-requisites, the pdfFontName attribute can contain one of the following values minus The name of a built-in PDF font from the above list. The name of a TTF file that can be located on disk at runtime when exporting to PDF. The real name of a registered font. The suffix of the key (the part after net. sf. jasperreports. export. pdf. font ) for a font registered with iText as a font file. Default Fonts and Inheritance Each text element inherits font and style attributes from its parent element, which in turn inherits these attributes from its parent. If no styles andor fonts are defined for elements, the default style (andor font - but this is now deprecated) declared in the ltjasperReportgt root element will be applied. Defining default styles or fonts in JasperReports is not mandatory. If no font is defined for a given element, the engine looks either for the inherited font attributes, or, if no attributes are found on this way, it looks for the net. sf. jasperreports. default. font. name property in the srcdefault. jasperreports. properties file. Its value defines the name of the font family to be used when font properties are not explicitly defined for a text element or inherited from its parent. The main default font properties and their values defined in the srcdefault. jasperreports. properties file are in the table below minus By default PDF fonts are not embedded. To demonstrate using fonts and font attributes in order to get a particular text appearance, lets write new report template (jasperreporttemplate. jrxml). The contents of the JRXML are as below. Save it to C:toolsjasperreports-5.0.1test directory. Here, we will display a text in the title of the report in various font formats. The java code to fill and generate the report is as given below. Lets save this file JasperFontsReportFill. java to C:toolsjasperreports-5.0.1testsrccomtutorialspoint directory. Here, we use an instance of JREmptyDataSource when filling reports to simulate a data source with one record in it, but with all the fields being null . Report Generation We will compile and execute the above file using our regular ANT build process. The contents of the file build. xml (saved under directory C:toolsjasperreports-5.0.1test) are as given below. The import file - baseBuild. xml is picked from chapter Environment Setup and should be placed in the same directory as the build. xml. Next, lets open command line window and go to the directory where build. xml is placed. Finally, execute the command ant - Dmain-classcom. tutorialspoint. JasperFontsReportFill (viewFullReport is the default target) as minus As a result of above compilation, a JasperViewer window opens up as shown in the screen given below minus Here, we can see that the text Welcome to TutorialsPoint is displayed in different font formats. Unicode Support In JasperReports, working with texts needs some dedicated tools to process both the character representations and the text formatting properties. Any text can be considered as a character sequence with a particular representation structure. The text appearance consists in both layout (and paragraph) and font settings. But while in most cases, the text layout remains invariant, font settings may change when running the report in different Locales. We know that different languages need different character sets with respect to specific characters representation. Therefore, working with texts means working with fonts. However, a detailed discussion about how to use fonts in JasperReports is available in the chapter Report Fonts . One of the main features concerning the text content in a given report is the possibility to internationalize it. It means, we can run the report in different localized environments, using different languages and other localization settings without any hardcoded modification. Character encoding is an important feature when a report is intended to be internationalized. Character Encoding A character is the smallest unit of writing conveying a meaningful information. It is an abstract concept, a character does not have a visual appearance. Uppercase Latin A is a different character from lowercase Latin a and from uppercase Cyrillic A and uppercase Greek Alpha. A visual representation of a character is known as a glyph . A certain set of glyphs is called a font . Uppercase Latin A, uppercase Cyrillic A and uppercase Greek Alpha may have identical glyphs, but they are different characters. At the same time, the glyphs for uppercase Latin A can look very different in Times New Roman, Gill Sans and Poetica chancery italic, but they still represent the same character. The set of available characters is called a character repertoire . The location (index) of a given character within a repertoire is known as its code position, or code point. The method of numerically representing a code point within a given repertoire is called the character encoding . Encodings are normally expressed in terms of octets. An octet is a group of eight binary digits, i. e. eight ones and zeros. An octet can express a numeric range between 0 and 255, or between 0x00 and 0xFF, to use hexadecimal notation. A Unicode is a character repertoire that contains most of the characters used in the languages of the world. It can accommodate millions of characters, and already contains hundreds of thousands. Unicode is divided into planes of 64K characters. The only one used in most circumstances is the first plane, known as the basic multilingual plane, or BMP. UTF-8 is the recommended encoding. It uses a variable number of octets to represent different characters. In a JRXML file, the encoding attribute is specified in the header. It is used at report compilation time to decode the XML content. For instance, if the report contains French words only and characters such as ccedil, eacute, acirc, then the ISO-8859-1 (a. k.a Latin-1) encoding is sufficient minus As seen above, ideally we can choose the encoding fit to the minimal character set, which can correctly represent all the characters in the document. But in case of Multilanguage documents (i. e. documents containing words spelled in several languages), one should choose the encoding adapted to the minimal character set, able to correctly represent all the characters in the document, even if they belong to different languages. One of the character encodings able to handle multilingual documents is the UTF-8 . used as default encoding value by JasperReports. The texts are usually kept in resource bundle files rather than within the document during internationalization. So, there are cases where the JRXML itself looks completely ASCII-compatible, but generated reports at runtime do contain texts unreadable with ASCII. As a result, for a certain type of document export formats (such as CSV, HTML, XHTML, XML, and text) one has to know the encoding for the generated document too. Different languages are supported by different character encodings. So each time, we need to run a report in a localized environment. Further, we have to know, which is the most appropriate character encoding for the generated document language. In this case, the encoding property defined in the JRXML file itself might be no more useful. To solve this kind of issues we can use an export customer property known as net. sf. jasperreports. export. character. encoding . This export custom property is default to UTF-8 and is present in JasperReports. This default value is set in the default. jasperreports. properties file. For more specific options at export time, the CHARACTERENCODING export parameter is also available. To demonstrate using unicode support in Jasperreports, lets write new report template (jasperreporttemplate. jrxml). Save it to C:toolsjasperreports-5.0.1test directory. Here, we will display a text in different languages using the Unicode characters (uXXXX). Any character encoded with UTF-8 can be represented using only its 4-digits hexadecimal code. For instance, the Greek letter can be written as u0393. When such a notation is encountered, the engine calls for the appropriate character representation in the character set, and only that particular character will be printed out. The contents of the JRXML are as below minus In the above file, we can see the presence of the UTF-8 encoding. Also the localized Unicode pieces of text are stored in document parameters. The java code to fill and generate the report is as below. Lets save this file JasperUnicodeReportFill. java to C:toolsjasperreports-5.0.1testsrccomtutorialspoint directory. Here we use an instance of JREmptyDataSource when filling reports to simulate a data source with one record in it, but with all the fields in this single record being null . Report Generation We will compile and execute the above file using our regular ANT build process. The contents of the file build. xml (saved under directory C:toolsjasperreports-5.0.1test) are as below. The import file - baseBuild. xml is picked from chapter Environment Setup and should be placed in the same directory as the build. xml. Next, lets open command line window and go to the directory where build. xml is placed. Finally, execute the command ant - Dmain-classcom. tutorialspoint. JasperUnicodeReportFill (viewFullReport is the default target) as follows minus As a result of above compilation, a JasperViewer window opens up as shown in the screen given below minus Here, we can see that the text being displayed is in different languages. Also we see that the languages are grouped together on the same page and also mixed into the same text element. Report Styles JasperReports has a feature ltstylegt which helps to control text properties in a report template. This element is a collection of style settings declared at the report level. Properties like foreground color, background color, whether the font is bold, italic, or normal, the font size, a border for the font, and many other attributes are controlled by ltstylegt element. Styles can extend other styles, and add to, or override properties of the parent style as well. Style Properties A ltstylegt element has many attributes. Some of the most commonly used are listed in the table given below minus Attribute and Description Conditional Styles In some situations, a style should be applied only when certain condition is met (for example, to alternate adjacent row colors in a report detail section). This can be achieved using conditional styles. A conditional style has two elements minus a Boolean condition expression a style The style is used only if the condition evaluates to true . Applying Styles to Report Elements Any type of report element can reference a report style definition using the style attribute. Hence, all the style properties declared by the style definition that are applicable to the current element will be inherited. To override the inherited values, style properties specified at the report element level can be used. Style Templates We can make a set of reports with a common look by defining the style at a common place. This common style template can then be referenced by the report templates. A style template is an XML file that contains one or more style definitions. Style template files used by convention the. jrtx extension, but this is not mandatory. A style template contains following elements minus ltjasperTemplategt minus This is the root element of a style template file. lttemplategt minus This element is used to include references to other template files. The contents of this element are interpreted as the location of the referred template file. ltstylegt minus This element is identical to the element with the same name from report design templates (JRXML files), with the exception that a style in a style template cannot contain conditional styles. This limitation is caused by the fact that conditional styles involve report expressions, and expressions can only be interpreted in the context of a single report definition. References to style templates are included in JRXML reports as lttemplategt elements. The style templates are loaded at report fill time, and style name references are resolved once all the templates have been loaded. When loading style templates and resolving style names to styles, a treegraph of style templates is created, the top of the tree being the set of styles defined in the report. On this tree, style name references are resolved to the last style that matches the name in a depth-first traversal. Lets try out the conditional styles and style templates. Lets add the lt style gt element alternateStyle to our existing report template (Chapter Report Designs ). Based on the condition, font color changes to blue for even count. We have also included a style template styles. jrtx . The revised report template (jasperreporttemplate. jrxml) is as follows. Save it to C:toolsjasperreports-5.0.1test directory minus The contents of style template styles. jrtx are as follows. Save it to C:toolsjasperreports-5.0.1test directory. The java codes for report filling remain unchanged. The contents of the file C:toolsjasperreports-5.0.1testsrccomtutorialspointJasperReportFill. java are as given below minus The contents of the POJO file C:toolsjasperreports-5.0.1testsrccomtutorialspointDataBean. java are as below minus The contents of the file C:toolsjasperreports-5.0.1testsrccomtutorialspointDataBeanList. java are as below minus Report Generation We will compile and execute the above file using our regular ANT build process. The contents of the file build. xml (saved under directory C:toolsjasperreports-5.0.1test) are as given below. The import file - baseBuild. xml is picked up from the chapter Environment Setup and should be placed in the same directory as the build. xml. Next, lets open command line window and go to the directory where build. xml is placed. Finally, execute the command ant - Dmain-classcom. tutorialspoint. JasperReportFill (viewFullReport is the default target) as minus As a result of above compilation, a JasperViewer window opens up as shown in the screen given below minus Here, we can see that the color of the font is changed to blue for even count (in column country). In the column name, the font color is changed to green (this style is referenced from the style template). Report Scriptlets We have seen in our previous chapters, data displayed on the report is usually fetched from report parameters and report fields. This data can be processed using the report variables and their expressions. There are situations when a complex functionality cannot be achieved easily using report expressions or variables. Examples of this may be complex String manipulations, building of Maps, or Lists of objects in memory or manipulations of dates using 3rd party Java APIs. For such situations, JasperReports provides us with a simple and powerful means of doing this with Scriptlets . Scriptlets are sequences of Java code that are executed every time a report event occurs. Values of report variables can be affected through scriptlets. Scriptlet Declaration We can declare a scriptlet in two ways minus Using lt scriptlet gt element. This element has name attribute and class attribute. The class attribute should specify the name of the class, which extends JRAbstractScriptlet class. The class must be available in the classpath at report filling time and must have an empty constructor, so that the engine can instantiate it on the fly. Using the attribute scriptletClass of the element lt jasperReport gt, in the report template (JRXML). By setting this attribute with fully qualified name of scriptlet (including the entire package name), we indicate that we want to use a scriptlet. The scriptlet instance, created with this attribute, acts like the first scriptlet in the list of scriptlets and has the predefined name REPORT. Scriptlet class A scriptlet is a java class, which must extend either of the following classes minus net. sf. jasperreports. engine. JRAbstractScriptlet minus This class contains a number of abstract methods that must be overridden in every implementation. These methods are called automatically by JasperReports at the appropriate moment. Developer must implement all the abstract methods. net. sf. jasperreports. engine. JRDefaultScriptlet minus This class contains default empty implementations of every method in JRAbstractScriptlet. A developer is only required to implement those methods heshe needs for hisher project. The following table lists the methods in the above class. These methods will be called by the report engine at the appropriate time, during report filling phase. Method and Description public void afterDetailEval() Called after each record in the detail section of the report is evaluated. Any number of scriptlets can be specified per report. If no scriptlet is specified for a report, the engine still creates a single JRDefaultScriptlet instance and registers it with the built-in REPORTSCRIPTLET parameter. We can add any additional methods that we need to our scriptlets. Reports can call these methods by using the built-in parameter REPORTSCRIPTLET. Global Scriptlets We can associate scriptlets in another way to reports, which is by declaring the scriptlets globally. This makes the scriptlets apply to all reports being filled in the given JasperReports deployment. This is made easy by the fact that scriptlets can be added to JasperReports as extensions. The scriptlet extension point is represented by the net. sf. jasperreports. engine. scriptlets. ScriptletFactory interface. JasperReports will load all scriptlet factories available through extensions at runtime. Then, it will ask each one of them for the list of scriptlets instances that they want to apply to the current report that is being run. When asking for the list of scriptlet instances, the engine gives some context information that the factory could use in order to decide, which scriptlets actually apply to the current report. Report Governors Governors are just an extension of global scriptlets that enable us to tackle a problem of report engine entering infinite loop at runtime, while generating reports. Invalid report templates cannot be detected at design time, because most of the time, the conditions for entering the infinite loops depend on the actual data that is fed into the engine at runtime. Report Governors help in deciding whether a certain report has entered an infinite loop and they can stop it. This prevents resource exhaustion for the machine that runs the report. JasperReports has two simple report governors that would stop a report execution based on a specified maximum number of pages or a specified timeout interval. They are minus net. sf. jasperreports. governors. MaxPagesGovernor minus This is a global scriptlet that is looking for two configuration properties to decide if it applies or not to the report currently being run. The configuration properties are minus net. sf. jasperreports. governors. TimeoutGovernor minus This is also a global scriptlet that is looking for the following two configuration properties to decide if it applies or not. The configuration properties are minus The properties for both governors can be set globally, in the jasperreports. properties file, or at report level, as custom report properties. This is useful because different reports can have different estimated size or timeout limits and also because you might want turn on the governors for all reports, while turning it off for some, or vice-versa. Lets write a scriptlet class ( MyScriptlet ). The contents of file C:toolsjasperreports-5.0.1testsrccomtutorialspointMyScriptlet. java are as follows minus Details of the above scriptlet class are as follows minus In the afterReportInit method, we set a value to the variable someVar this. setVariableValue(someVar, new String(This variable value was modified by the scriptlet.)). At the end of the class, an extra method called hello has been defined. This is an example of a method that can be added to the Scriptlet that actually returns a value, rather than setting a Variable. Next, we will add the scriptlet class reference in our existing report template (Chapter Report Designs ). The revised report template (jasperreporttemplate. jrxml) are as follows. Save it to C:toolsjasperreports-5.0.1test directory minus The details of the revised report template is given below minus We have referenced the MyScriptlet class in the attribute scriptletClass of ltjasperReportgt element. Scriptlets can only access, but not modify the report fields and parameters. However, scriptlets can modify report variable values. This can be accomplished by calling the setVariableValue() method. This method is defined in JRAbstractScriptlet class, which is always the parent class of any scriptlet. Here, we have defined a variable someVar . which will be modified by the MyScriptlet to have the value This value was modified by the scriptlet . The above report template has a method call in the Summary band that illustrates how to write new methods (in scriptlets) and use them in the report template. ( P. hello() ) The java codes for report filling remain unchanged. The contents of the file C:toolsjasperreports-5.0.1testsrccomtutorialspointJasperReportFill. java are as given below minus The contents of the POJO file C:toolsjasperreports-5.0.1testsrccomtutorialspointDataBean. java are as given below minus The contents of the file C:toolsjasperreports-5.0.1testsrccomtutorialspointDataBeanList. java are as given below minus Report Generation We will compile and execute the above file using our regular ANT build process. The contents of the file build. xml (saved under directory C:toolsjasperreports-5.0.1test) are as given below. The import file - baseBuild. xml is picked up from the chapter Environment Setup and should be placed in the same directory as the build. xml. Next, lets open command line window and go to the directory where build. xml is placed. Finally, execute the command ant - Dmain-classcom. tutorialspoint. JasperReportFill (viewFullReport is the default target) as minus As a result of above compilation, a JasperViewer window opens up as shown in the screen given below minus Here we see two messages are displayed from MyScriptlet class minus In title section minus This variable value was modified by the scriptlet At the bottom minus Hello Im the reports scriptlet object. Create SubReports Subreports are one of the nice features of the JasperReports. This feature allows incorporating a report within another report, that is, one report can be a subreport of another. Subreports help us keep report designs simple, as we can create many simple reports and encapsulate them into a master report. Subreports are compiled and filled just like normal reports. Any report template can be used as a subreport when incorporated into another report template, without anything changed inside (of the report template). Subreports are like normal report templates. They are in fact net. sf. jasperreports. engine. JasperReport objects, which are obtained after compiling a net. sf. jasperreports. engine. design. JasperDesign object . ltsubreportgt Element A ltsubreportgt element is used when introducing subreports into master reports. Here is the list of sub-elements in the ltsubreportgt JRXML element. ltparametersMapExpressiongt minus This is used to pass a map containing report parameters to the subreport. The map is usually obtained from a parameter in the master report, or by using the built-in REPORTSPARAMETERSMAP parameter to pass the parent reports parameters to the subreport. This expression should always return a java. util. Map object in which the keys are the parameter names. ltsubreportParametergt minus This element is used to pass parameters to the subreport. It has an attribute name . which is mandatory. ltconnectionExpression gt minus This is used to pass a java. sql. Connection to the subreport. It is used only when the subreport template needs a database connection during report filling phase. ltdataSourceExpressiongt minus This is used to pass a datasource to the subreport. This datasource is usually obtained from a parameter in the master report or by using the built-in REPORTDATASOURCE parameter to pass the parent reports datasource to the subreport. The elements ( connectionExpression and dataSourceExpression ) cannot be present at the same time in a ltsubreportgt element declaration. This is because we cannot supply both a data source and a connection to the subreport. We must decide on one of them and stick to it. ltreturnValuegt minus This is used to assign the value of one of the subreports variables to one of the master reports variables. This sub element has attributes as follows minus subreportVariable minus This attribute specifies the name of the subreport variable whose value is to be returned. toVariable minus This attribute specifies the name of the parent report variable whose value is to be copiedincremented with the value from the subreport. calculation minus This attribute can take values. Nothing, Count, DistinctCount, Sum, Average, Lowest, Highest, StandardDeviation, Variance. Default value for attribute calculation is Nothing. incrementerFactoryClass minus This attribute specifies the factory class for creating the incrementer instance. ltsubreportExpressiongt minus This indicates where to find the compiled report template for the subreport. This element has a class attribute. The class attribute can take any of these values:java. lang. String, java. io. File, java. URL, java. io. InputStream, net. sf. jasperreports. engine. JasperReport. Default value is java. lang. String . isUsingCache minus This is an attribute of the ltsubreportgt element. This is a Boolean, when set to true . the reporting engine will try to recognize previously loaded subreport template objects, using their specified source. This caching functionality is available only for subreport elements that have expressions returning java. lang. String objects as the subreport template source, representing file names, URLs, or classpath resources. Let take up a simple example to demonstrate creation of subreports using JRDataSource. Lets first write two new report templates, one being subreport and the other Master report. The contents of the subreport (addressreporttemplate. jrxml) template is as given below. Save it to C:toolsjasperreports-5.0.1test directory. As we use a data source, we need to write a corresponding POJO file SubReportBean. java as shown below. Save it to directory C:toolsjasperreports-5.0.1testsrccomtutorialspoint minus Here, we have declared two fields city and street and respective getter and setter methods are defined. Now, lets update our existing DataBean file. We will add a new field subReportBeanList . which is a java. util. List. This field will hold the list of SubReportBean objects. The contents of the file DataBean are as below. Save it to directory C:toolsjasperreports-5.0.1testsrccomtutorialspoint. Lets now update the file C:toolsjasperreports-5.0.1testsrccomtutorialspoint DataBeanList. java . The contents of this file are as minus In the method produce() in the above file, we are setting the list of SubReportBean. Now, lets write a new master report template (jasperreporttemplate. jrxml). Save this file to directory C:toolsjasperreports-5.0.1test . The contents for this file are as below minus In the above template, we have defined a new parameter SUBREPORTDIR, which defines the path of the subreport. We have defined a field subReportBeanList of type java. util. List, which corresponds to property in the file DataBean. The element ltsubreportgt has sub-element ltdataSourceExpressiongt. We have put the list subReportBeanList in an instance of JRBeanCollectionDataSource. In the sub-element ltsubreportExpressiongt, we have given the subreport name (AddressReport. jasper). Now, lets write a new class CreateReport to compile and execute our report template. The contents of file C:toolsjasperreports-5.0.1testsrccomtutorialspointCreateReport. java are as given below minus Here, we see that we are compiling both the master and sub report templates and passing the master report (.jasper) file for the report filling. Report Generation Now, all our files are ready, lets compile and execute them using our regular ANT build process. The contents of the file build. xml (saved under directory C:toolsjasperreports-5.0.1test) are as given below. The import file - baseBuild. xml is picked up from the chapter Environment Setup and should be placed in the same directory as the build. xml. Next, lets open command line window and go to the directory where build. xml is placed. Finally, execute the command ant - Dmain-classcom. tutorialspoint. CreateReport (viewFullReport is the default target) as follows minus As a result of above compilation, a JasperViewer window opens up as shown in the screen given below minus Here, we can see that the attributes Name, Country, and Address are displayed. Creating Charts Earlier people had to rely on scriptlets to gather the chart data and render the chart using an image element in the report template. JasperReports makes it simple now, as it has a built-in support for charts using the new chart component. Using a new chart component, user needs to apply only the visual settings and define expressions that will help build the chart dataset. JasperReports uses JFreeChart as the underlying charting library. When configuring a new chart component, following three components are involved minus The overall chart component. The chart dataset (which groups chart data-related settings). The chart plot (which groups visual settings related to the way the chart items are rendered). JasperReports currently supports the following types of charts: Pie, Pie 3D, Bar, Bar 3D, XY Bar, Stacked Bar, Stacked Bar 3D, Line, XY Line, Area, XY Area, Stacked Area, Scatter, Bubble, Time Series, High-Low-Open-Close, Candlestick, Multiple Axis, Meter, Thermometer, and Gantt. Chart Properties Charts are normal report elements, so they share some of their properties with all the other report elements. There is a JRXML element called lt chart gt, used to create all type of charts. This element groups special chart-specific settings that apply to all types of charts. Chart Sub-Elements The sub-elements of ltchartgt element are minus ltreportElementgt minus These are displayable objects like static texts, text fields, images, lines, and rectangles that you put in your report template sections. ltBoxgt minus This element is used to surround charts by a border thats customizable on each side. ltchartTitlegt minus This element is used to place the title of the chart. The position attribute decides the title position of the chart in the report. This element has attributes - Position (Values could be Top . Bottom . Left . Right . Deafult value is Top ), color . ltchartTitlegt has font and titleExpression as subelements. ltchartSubtitlegt minus This element is used to place the subtitle of the chart. This element has attribute - color . ltchartSubtitlegt has font and subtitleExpression as subelements. ltchartLegendgt minus The element can control the font-related properties as well as the text color and the background color of the chart legend using this element. This element has attributes - textColor and backgroundColor . ltanchorNameExpressiongt minus This element creates the target for the anchor. lthyperlinkReferenceExpressiongt minus This element contains a report expression indicating the name of the external resource (usually a URL). lthyperlinkAnchorExpressiongt minus Hyperlink points to an anchor in an external resource. lthyperlinkPageExpressiongt minus Hyperlink points to a page in the current report. lthyperlinkTooltipExpressiongt minus This element controls the ToolTip of hyperlink. The type of the expression should be java. lang. String . lthyperlinkParametergt minus This element when present generates a final hyperlink depending on the parameter values. Chart attributes Attributes in the ltchartgt element available for all chart types are minus isShowLegend minus This attribute is used to determine, if a chart legend will be displayed on the report. Values could be true . or false . Default value is true . evaluationTime minus Determines when the charts expression will be evaluated. Values could be Now . Report . Page . Column . Group . Band . Default value is Now . evaluationGroup minus This attribute determines the name of the group to be used to evaluate the charts expressions. The value for this attribute must match the name of the group, we would like to use as the charts evaluation group. hyperlinkType minus This attribute can hold any text value. Default value is None . This means, neither the text fields nor the images represent hyperlinks, even if the special hyperlink expressions are present. hyperlinkTarget minus This attribute helps to customize the behavior of the specified link when it is clicked in the viewer. Values could be Self . or Blank . Default value is Self . bookmarkLevel minus This attribute when set to a positive integer, generates bookmarks in the reports exported to PDF. Default value is 0 . customizerClass minus This is the name of a class (optional) that can be used to customize the chart. The value for this element must be a String containing the name of a customizer class. Chart customization As mentioned above, JasperReports uses JFreeChart as the underlying charting library. JFreeChart contains features that are directly not supported by JasperReports. We can take advantage of these features by supplying a customizer class via the customizerClass attribute in ltchartgt element. A customizer class is nothing, but an implementation of the net. sf. jasperreports. engine. JRChartCustomizer interface. The easiest way to implement this interface is by extending the net. sf. jasperreports. engine. JRAbstractChartCustomizer class and thus having access to parameters, fields, and variables for more flexible chart customization based on report data. Chart Datasets One of the common properties across all chart types is lt dataset gt element. Chart datasets help mapping report data and retrieving chart data at runtime. Each chart type contains different sub-elements to define charts expressions. These expressions define the data used to generate the chart. All of these sub-elements contain a ltdatasetgt element that defines when the charts expressions are evaluated and reset. Several types of chart datasets are available in JasperReports because each type of chart works with certain datasets: Pie, Category, XY, Time Series, Time Period, XYZ, and High-Low. Each of these dataset types implements net. sf. jasperreports. engine. JRChartDataset interface that define chart datasets. All chart datasets initialize and increment in the same way however, they differ only in the type of data or data series they map. Dataset Properties Table given below summarizes the attributes of the element ltdatasetgt minus JasperReports - Crosstabs JasperReports - Internationalization
Comments
Post a Comment