2009-08-06: الافراج عن 0.6.0 صدر 2009-05-22: الافراج عن 0.5.0 صدر 2009-03-16: الافراج عن 0.5.0 بيتا. 2008-06-20: الإصدار 0.4.1، إعادة إطلاق موقع ويكي وإدراج المنتديات كصفحات مضمنة: منتدى المستخدمين ومنتدى المطورين. استمتع 2008-05-04 الملحق المحدودة و لافابلاست يسرنا أن نعلن عن الإصدار 0.4.0 من ستاتسفن. مزيد من التفاصيل حول هذا بلوق و التغيير. 2007-03-10 أخبار. كجزء من الإصدار 0.3.1، أطلقنا سلسلة من العروض لبعض المشاريع المعروفة: التخريب، النمل، Log4J، الربيع العميل ريتش، السبات 3، جودا الوقت، روبي، رائع، غرايلز وفيليكس لتبدأ. المضي قدما، أعترف بذلك، كنت أريد دائما أن يعرف من فعل ما ومتى على تلك المشاريع. تحذير . إذا كنت لا تستخدم اللغة الإنجليزية، يرجى تعيين متغير بيئة لانغ إلى إنوس عند تشغيل التطبيق حتى نقوم بحل بعض القضايا i18n مع ستاتسفن (المكالمة إلى سفن ديف بإرجاع سلسلة المترجمة التي قد تؤدي إلى بعض النتائج لا يتم مؤقتا، النتائج صحيحة ولكن ستاتسن سوف يطلب لهم مرة أخرى في المرة القادمة). 2007-02-07: هل تريد المساعدة هل تفكر في استبدال الاستدعاءات سطر الأوامر مع المكالمات إلى سفنكيت (سابقا جافاسفن). تريد أن تكتب تنفيذ النموذج ونرى جيدا كيف ينفذ إعلامنا 2007-01-12: الإصدار 0.3.0 هو في سفن ويضيف 2 تقارير (ريبوماب و لوكورن) وكذلك تحديد عدد من القضايا مع نقل الملفات والدلائل وحذف تلك. مزيد من التفاصيل حول هذه الصفحة. 2006-11-28: الإصدار 0.2.0 هو خارج والآن يدعم هتمل و شدوك جيل لتسهيل التكامل مع مافين (انظر التقارير هنا). وكان من دواعي سرورنا أن نذكر أن هناك مافين 2 المساعد باستخدام ستاتسفن، فإنه يتوفر في ستات-scm. sourceforge. تويت تويت من المؤلفين لذا، ما هو ستاتسفن إحصاءات كبيرة ل سفن ستاتسفن يسترد المعلومات من مستودع سوبفيرزيون ويولد الجداول والمخططات المختلفة التي تصف تطوير المشروع، على سبيل المثال. الجدول الزمني لخطوط خطوط التعليمات البرمجية من التعليمات البرمجية لكل مطور النشاط حسب الوقت على مدار الساعة المؤلفون نشاط مؤلف النشاط لكل وحدة الكاتب أحدث تلتزم مع وصلات إلى إحصائيات فيوفك لكل دليل عدد الملفات متوسط حجم الملف أكبر الملفات الملفات مع معظم المراجعات مقاسات الدليل مستودع العلامات عدد من لوك لكل إصدار. شجرة مستودع مع عدد الملفات وخطوط التعليمات البرمجية لوك وتغيير تطور لوك ومقدار التغيير في اليوم الواحد إعادة رسم خريطة العرض الهرمي الديناميكي من الريبو الخاص بك لمدة 30 يوما الماضية الإصدار الحالي من ستاتسفن يولد مجموعة ثابتة من وثائق هتمل تحتوي على الجداول والرسوم البيانية الصور. ستاتسفن هو برنامج مفتوح المصدر، صدر بموجب شروط لغبل، استنادا ستاتكفس. يستخدم ستاتسفن جفريشارت لتوليد charts. Where هو دليل دليل متاح على الانترنت كما ويكي وأنه هو ما يصل إلى تاريخ وشاملة كما تريد أن تكون. مثال سريع ل مافين 1 قبل تشغيل الموقع مافين (أو ببساطة مافين شدوك)، يمكنك إنشاء ملفات زدوك عن طريق تشغيل: (لا ننسى - v). سيولد هذا المثال شدوك في الدليل سيتستاتسفن، علامة 0.2.0، 0.1.3، 0.1.2، 0.0.9، استبعاد qalab. xml وغيرها. بعد ذلك سوف يتم التقاط زدوك من قبل موقع مافين أو مافين شدوك. يرجى ملاحظة أنه من أجل استخدام العلامات، يجب عليك استخدام ملف سجل ليس على مستوى الجذع ولكن فقط أعلاه، من أجل تضمين دليل العلامات. في الوقت الراهن، ستاتسفن يعمل فقط مع دليل العلامات. مثال سريع على تفريغ جديد هناك منشأة تفريغ جديدة (لا ننسى - v). وهذا سيولد كمية كبيرة من الناتج ولكن في نهاية هذا، إذا كان يظهر موافق على كل شيء من المرجح أن ستاتسن فهمت بشكل صحيح مستودع الخاص بك: جاسبيريبورتس - دليل سريع جاسبيريبورتس - الشروع في العمل جاسبيريبورتس - إعداد البيئة جاسبيريبورتس - دورة الحياة جاسبيريبورتس - تصاميم جاسبيريبورتس - تجميع تقرير تصميم جاسبيريبورتس - تعبئة تقارير جاسبر تقرير - عرض أمبير طباعة تقارير جاسبيريبورتس - تصدير تقارير تقارير معلمات إذا تم تعيينها إلى java. lang. Boolean. TRUE سيتم إنشاء التقرير على صفحة واحدة طويلة وكسر صفحة لن يحدث. دعونا تمرير ريبورتتيتل والمؤلف إلى التقرير (التي تم إنشاؤها بواسطة JasperReportFill. java). ملف منقح C: toolsjasperreports-5.0.1testsrccomtutorialspointJasperReportFill. java هو كما يلي ناقص محتويات ملف بوجو C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBean. java هي على النحو التالي ناقص محتويات الملف C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBeanList. java هي كما أعطيت أدناه ناقص يضيف معلمات لوت ريبورتتيتل غ و لوت المؤلف غ إلى قالب التقرير الموجود لدينا (الفصل تقرير تصاميم). سيتم عرض عنوان التقرير والمؤلف في بداية التقرير. نموذج التقرير المنقح (jasperreporttemplate. jrxml) هو كما يلي. حفظه إلى C: تولسجاسبيريبورتس-5.0.1test الدليل ناقص الجيل تقرير سنقوم بتجميع وتنفيذ الملف أعلاه باستخدام لدينا العادية عملية بناء أنت. محتويات ملف build. xml (المحفوظة تحت الدليل C: تولسجاسبيريبورتس-5.0.1test) هي على النحو التالي. يتم استيراد ملف الاستيراد - baseBuild. xml من "إعداد البيئة الفصل" ويجب أن توضع في نفس الدليل مثل build. xml. بعد ذلك، يتيح فتح نافذة سطر الأوامر والذهاب إلى الدليل حيث يتم إنشاء build. xml. وأخيرا، تنفيذ الأمر النمل - Dmain-classcom. tutorialspoint. JasperReportFill (فيفولريبورت هو الهدف الافتراضي) كما يلي ناقص ونتيجة لتجميع أعلاه، يفتح نافذة جاسرفيور كما هو مبين في الشاشة التالية ناقص هنا، نرى أن ريبورتتيتل قائمة جهات الاتصال والمؤلف أعدتها مانيشا يتم عرضها في بداية التقرير. مصادر بيانات التقرير تعد قاعدة البيانات قاعدة بيانات منظمة. أثناء توليد التقرير، يحصل محرك جاسبيريبورتس البيانات من داتاسورسز. ويمكن الحصول على البيانات من قواعد البيانات، وملفات شمل، صفائف من الكائنات، وجمع الكائنات. رأينا في الفصل ملء التقارير. تتوقع الطريقة فيلريبورتكسس () الحصول على مصدر بيانات التقرير الذي يجب تعبئة في شكل كائن net. sf. jasperreports. engine. JRDataSource أو java. sql. Connection (عندما يتم العثور على بيانات التقرير في قاعدة البيانات العلائقية). واجهة جرداتاسورس لديها طريقتين فقط، والتي يجب تنفيذها ناقص المنطقية العامة التالي () يلقي جريكسيبتيون في وقت ملء التقرير، يتم استدعاء هذا الأسلوب على كائن مصدر البيانات بواسطة محرك التقارير عند تكرار من خلال البيانات. كائن عام جيتفيلدفالو (جرفيلد جرفيلد) يلقي جريكسيبتيون توفر هذه الطريقة قيمة لكل حقل تقرير في سجل مصدر البيانات الحالي. الطريقة الوحيدة لاسترداد البيانات من مصدر البيانات هي باستخدام حقول التقرير. هناك العديد من عمليات التنفيذ الافتراضية لواجهة جرداتاسورس، اعتمادا على الطريقة، يتم الحصول على السجلات في مصدر البيانات. تطبيقات مصدر البيانات يلخص الجدول أدناه مصادر البيانات وفئات التنفيذ الخاصة بها ناقص جدبك مصادر البيانات الفئة جريسولتسيتداتاسورس يلف كائن java. sql. ResultSet. هذه هي أكثر عمليات استخدام مصدر البيانات شيوعا عند استخراج بيانات التقرير من قاعدة بيانات علائقية. إذا تم تمرير java. sql. Connection إلى المحرك بدلا من ذلك، فإنه ينفذ أولا الاستعلام ذات الصلة ويخزن الكائن java. sql. ResultSet الذي تم إرجاعه في مثيل جريسولتسيتداتاسورس. فئات بيانات جافابين فئات جرباناريداتاسورس و جربانكولكتيونداتاسورس تمثل تطبيقات التي يمكن التفاف صفائف ومجموعات من الكائنات جافابين. سيتم اعتبار كل كائن داخل المصفوفة أو المجموعة سجلا واحدا في هذا النوع من مصدر البيانات. يتم إجراء التعيين بين خاصية جافابين معينة وحقل التقرير المقابل بواسطة مصطلحات التسمية. يجب أن يكون اسم حقل التقرير هو نفس اسم الخاصية جافابين كما هو محدد من قبل مواصفات جافابينز. في جميع الأمثلة من هذا البرنامج التعليمي، استخدمنا جربانكولكتيونداتاسورس. مصادر البيانات المستندة إلى الخريطة فئات التنفيذ جرمبارايداتاسورس و جرمكولكتيونداتاسورس مفيدة إذا كان التطبيق الأصل بالفعل بتخزين بيانات التقارير المتوفرة في الذاكرة كائنات java. util. Map. ويعتبر كل كائن خريطة في الصفيف ملفوفة أو مجموعة سجل الظاهري في مصدر البيانات، ويتم استخراج قيمة كل حقل تقرير من الخريطة باستخدام حقل التقرير المسمى بالمفتاح. مصادر البيانات تابلموديل في العديد من التطبيقات من جانب العميل، يتم عرض البيانات في شكل جدول. أحد المتطلبات الشائعة في العديد من التطبيقات هو السماح للمستخدم بطباعة هذا الشكل المجدول كتقرير. فئة التنفيذ جرتابليموديلداتاسورس يجعل مهمة توليد تقارير من شكل جدول تافهة لتطبيقات سوينغ. يلتف هذا الفئة كائن javax. swing. table. TableModel. يمكن الوصول إلى الأعمدة الموجودة في كائن تابليموديل ملفوفة إما بأسمائهم أو بواسطة الفهارس التي تستند إلى 0. شمل مصادر البيانات كلاس جركملداتاسورس هو تطبيق مصدر بيانات يستند إلى دوم، والذي يستخدم تعبيرات زباث لتحديد بيانات من مستند شمل. يتم تمثيل السجلات في مصدر بيانات شمل بعناصر العقدة المحددة من خلال تعبير زباث. يتم استرداد قيم الحقل من كل سجل باستخدام تعبير زباث الذي يوفره وصف الحقل (عنصر لتفيلدسكريبتيونغت في جركسمل). زباث هي لغة تستخدم للتنقل عبر سمات وعناصر وثائق شمل. يمكن العثور على مزيد من المعلومات حول زباث في w3.orgTRxpath. مصادر بيانات كسف يمثل جركسفداتاسورس تنفيذ لمصادر البيانات، التي تسترد بياناتها من ملفات نصية منظمة عادة كسف. يتم استرداد قيم الحقول باستخدام فهرس الأعمدة. مصادر بيانات زلس يمثل جركلسداتاسورس تنفيذ لمصادر البيانات، والتي تقوم باسترجاع بياناتها من وثائق إكسيل. ويستند أيضا تعيين حقل التقرير لتنفيذ مصدر البيانات هذا إلى فهرس العمود الميداني. مصادر البيانات الفارغة فئة جريمبتيداتاسورس. يحاكي مصدر بيانات مع عدد معين من السجلات الفارغة الظاهري في الداخل. يتم استخدامه من قبل أدوات واجهة المستخدم لتقديم وظيفة معاينة التقرير الأساسية، أو في قوالب تقرير خاص، أو لأغراض الاختبار والتصحيح. مصادر البيانات ريويندابل يقوم net. sf. jasperreports. engine. JRRewindableDataSource بتمديد واجهة جرداتاسورس الأساسية. ويضيف طريقة واحدة فقط، تسمى موففيرست ()، إلى واجهة. الغرض من هذه الطريقة نقل المؤشر إلى العنصر الأول في مصدر البيانات. مصادر بيانات ريويندابل مفيدة عند العمل مع التقارير الفرعية الموضوعة داخل نطاق غير مسموح تقسيم إلى الإعداد إسسبليتالويدفالس وليس هناك مساحة كافية على الصفحة الحالية للتقرير الفرعي ليتم عرضها. جميع عمليات إعادة تصدير مصدر البيانات أعلاه قابلة لإعادة الترجيع باستثناء جريسولتسيتداتاسورس. كما أنه لا يدعم نقل مؤشر سجل مرة أخرى. هذا يطرح مشكلة فقط إذا تم استخدام مصدر البيانات هذا يدويا للف java. sql. ResultSet قبل تمريره إلى التقرير الفرعي. لا توجد مشكلة، إذا كان استعلام سكل موجود في قالب التقرير الفرعي، حيث سيقوم المحرك بتنفيذ مرة أخرى عند إعادة تشغيل التقرير الفرعي في الصفحة التالية. مزودو البيانات المصدر مكتبة جاسبيريبورتس لديها واجهة net. sf. jasperreports. engine. JRDataSourceProvider. ويساعد ذلك في إنشاء عناصر مصدر البيانات والتخلص منها. عند إنشاء قالب تقرير باستخدام أدوات واجهة المستخدم الرسومية، هناك حاجة إلى أداة خاصة لتخصيص مصدر بيانات التقارير. جرداتاسورسيبروفيدر هو الطريقة القياسية لتوصيل مصادر البيانات المخصصة إلى أداة تصميم. يجب تنفيذ مخصص لهذه الواجهة تنفيذ الأساليب التالية التي تسمح بإنشاء كائنات مصدر البيانات والتخلص منها وأيضا أساليب لإدراج حقول التقارير المتوفرة داخل مصدر البيانات إذا كان ذلك ممكنا ناقص حقول تقارير حقول التقارير هي العناصر التي تمثل تعيين البيانات بين مصدر البيانات ونموذج التقرير. يمكن الجمع بين الحقول في تعبيرات التقرير للحصول على الإخراج المطلوب. يمكن أن يحتوي نموذج التقرير على عناصر صفر أو أكثر من لاتفيلدغت. عند إعلان حقول التقرير، يجب أن يوفر مصدر البيانات بيانات مناظرة لجميع الحقول المحددة في قالب التقرير. إعلان الحقل يتم تنفيذ الإعلان الميداني كما هو موضح أدناه ناقص سمة الاسم السمة نيم لعنصر لتفيلدغت إلزامية. ويشير إلى الحقل في تعبيرات التقرير بالاسم. سمة الفئة تحدد السمة كلاس اسم الفئة لقيم الحقل. القيمة الافتراضية هي java. lang. String. يمكن تغيير هذا إلى أي فئة متوفرة في وقت التشغيل. بغض النظر عن نوع حقل التقرير، المحرك يعتني الصب في التعبيرات التقرير الذي يستخدم F رمزية، وبالتالي جعل يلقي اليدوية لا لزوم لها. الحقل الوصف عنصر لتفيلدديسسيبتيونغ هو عنصر اختياري. هذا مفيد جدا عند تنفيذ مصدر بيانات مخصص. على سبيل المثال، يمكننا تخزين مفتاح أو بعض المعلومات، التي يمكننا من خلالها استرداد قيمة الحقل من مصدر البيانات المخصص في وقت التشغيل. باستخدام عنصر لتفيلدزسيبتيونغت بدلا من اسم الحقل، يمكنك بسهولة التغلب على قيود اصطلاحات تسمية المجال عند استرداد قيم الحقل من مصدر البيانات. وفيما يلي قطعة من التعليمات البرمجية من ملف جركسمل الموجود لدينا (الفصل تقرير تصاميم). هنا، يمكننا أن نرى استخدام الاسم. صف دراسي . و فيلدسكريبتيون العناصر. حقول التصنيف في الأوقات التي يتطلب فيها فرز البيانات وتنفيذ مصدر البيانات لا يدعمه (على سبيل المثال مصدر بيانات كسف)، يدعم جاسبيريبورتس فرز مصدر البيانات المستند إلى الحقل في الذاكرة. يمكن أن يتم الفرز باستخدام عنصر واحد أو أكثر من عناصر لتسورتفيلدغت في قالب التقرير. إذا تم تحديد حقل نوع واحد على الأقل أثناء عملية ملء التقرير يتم تمرير مصدر البيانات إلى مثيل جرسورتابلداتاسورس. هذا بدوره، جلب كافة السجلات من مصدر البيانات، ينفذ في الذاكرة فرز وفقا الحقول المحددة، ويحل محل مصدر البيانات الأصلي. يجب أن يكون اسم حقل النوع مطابقا لاسم حقل التقرير. الحقول المستخدمة لفرز يجب أن يكون أنواع تنفيذ java. utilparable. يتم تنفيذ فرز النظام الطبيعي لجميع الحقول باستثناء تلك من نوع java. lang. String (لنوع سلسلة، الموافق المقابلة لملء التقرير يستخدم لغة). عند تحديد العديد من الحقول، سيتم تنفيذ الفرز باستخدام الحقول كمفاتيح فرز بالترتيب الذي تظهر به في قالب التقرير. يوضح المثال التالي ميزة الفرز. سورتيد ريبورت إكسامبل يتيح إضافة عنصر لوت إلى عنصر غ الموجود في نموذج تقريرنا الحالي (تصاميم تقرير الفصل). يتيح فرز بلد الحقل في ترتيب تنازلي. نموذج التقرير المنقح (jasperreporttemplate. jrxml) هو كما يلي. حفظه إلى C: تولسجاسبيريبورتس-5.0.1test ديركتوري ناقص رموز جافا لملء التقرير لا تزال دون تغيير. محتويات الملف C: toolsjasperreports-5.0.1testsrccomtutorialspointJasperReportFill. java هي كما هو موضح أدناه ناقص محتويات ملف بوجو C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBean. java هي كما هو موضح أدناه ناقص محتويات الملف C: تولسجاسبريبورتس-5.0. 1testsrccomtutorialspointDataBeanList. java هي كما هو موضح أدناه ناقص جيل التقرير سوف نقوم بتجميع وتنفيذ الملف أعلاه باستخدام لدينا العادية عملية بناء أنت. محتويات الملف build. xml (المحفوظة تحت الدليل C: تولسجاسبيريبورتس-5.0.1test) كما هو موضح أدناه. يتم استيراد ملف الاستيراد - baseBuild. xml من فصل إعداد البيئة ويجب أن توضع في نفس الدليل مثل build. xml. بعد ذلك، يتيح فتح نافذة سطر الأوامر والذهاب إلى الدليل حيث يتم إنشاء build. xml. وأخيرا، تنفيذ الأمر النملة - Dmain-classcom. tutorialspoint. JasperReportFill (فيوفولريبورت هو الهدف الافتراضي) كما يلي ناقص ونتيجة لتجميع أعلاه، يفتح نافذة جاسرفيور كما هو مبين في الشاشة أدناه ناقص هنا، يمكننا أن نرى أن يتم ترتيب أسماء البلدان بترتيب تنازلي أبجديا. تقرير التعبيرات تقرير التعبير هي ميزات قوية من جاسبيريبورتس، والتي تسمح لنا لعرض البيانات المحسوبة على التقرير. البيانات المحسوبة هي البيانات التي ليست بيانات ثابتة ولا يتم تمريرها على وجه التحديد كمعلمة تقرير أو حقل مصدر بيانات. يتم إنشاء تعبيرات التقرير من الجمع بين معلمات التقرير والحقول والبيانات الثابتة. يتم استخدام لغة جافا لكتابة تعبيرات التقرير بشكل افتراضي. لغات البرمجة الأخرى للتعبيرات تقرير مثل لغة البرمجة رائع، جافا سكريبت، أو النصي بينشيل معتمدة من قبل جامعي جاسبيريبورتس المجمعين. سيشرح لك هذا الفصل ناقص كيفية عمل تعبيرات التقارير، على افتراض أنها قد كتبت باستخدام لغة جافا فقط. في قالب تقرير جركسمل، هناك العديد من العناصر التي تعرف تعبيرات ناقص لتفاريابكسريسريونغت لتينيتيالفالويكسبريسيونغ لتروبريسكسيريونغت لتبرينتكسريبيريونغت لتيماجكسريسيونغت تكستفيلدكسريسيونغيت إعلان التعبير أساسا، جميع تعبيرات التقرير تعبيرات جافا التي يمكن الرجوع إلى حقول التقرير ومتغيرات التقرير معلمات التقرير. مرجع المجال في التعبير لاستخدام مرجع حقل تقرير في تعبير، يجب أن يتم وضع اسم الحقل بين F وتسلسل الأحرف، كما هو موضح أدناه ناقص التالي هو قطعة من التعليمات البرمجية من ملف جركسمل الموجود لدينا (الفصل تقرير تصاميم) ناقص متغير المرجع في التعبير للإشارة إلى متغير في تعبير، يجب أن نضع اسم المتغير بين V وكما هو موضح في المثال الموضح أدناه ناقص مرجع المعلمة في التعبير للإشارة إلى معلمة في تعبير، يجب وضع اسم المعلمة بين P وكما هو مبين في المثال الوارد أدناه ناقص التالي هو قطعة من التعليمات البرمجية من ملف جركسمل الموجود لدينا، مما يدل على الإشارة من المعلمة في تعبير. (جركسمل من الفصل تقرير تصاميم) ناقص كما رأيت أعلاه، المعلمة، الحقل، ومراجع متغير هي في الواقع كائنات جافا الحقيقية. بمعرفة فئتها من المعلمة أو الحقل أو إعلان متغير المحرز في قالب التقرير، يمكننا حتى استدعاء أساليب على هذه المراجع الكائن في التعبيرات. يوضح المثال التالي ناقص كيفية استخراج وعرض الحرف الأول من حقل التقرير java. lang. String الاسم ناقص حزمة الموارد مرجع في التعبير للإشارة إلى مورد في تعبير، يجب وضع المفتاح بين R وكما هو موضح في المثال المعطى أدناه ناقص استنادا إلى اللغة التي توفرها وقت التشغيل والمفتاح report. title، يتم تحميل حزمة الموارد المرتبطة قالب التقرير. وبالتالي، يتم عرض عنوان التقرير عن طريق استخراج قيمة سلسلة من حزمة المورد. ويمكن الاطلاع على المزيد عن التدويل في الفصل الدولي. حاسبة آلة حاسبة هي كيان في جاسبيريبورتس، الذي يقيم التعابير والزيادات المتغيرات أو مجموعات البيانات في وقت ملء التقرير. خلال عملية التجميع، يتم إنتاج المعلومات وتخزينها في تقرير تجميع من قبل مترجم. يتم استخدام هذه المعلومات خلال الوقت ملء التقرير لبناء مثيل من الطبقة net. sf. jasperreports. engine. fill. JRCalculator. يتم إنشاء ملف المصدر جافا وتصنيفها من قبل القائم على جافا القائمون على التقرير على الطاير. هذه الفئة التي تم إنشاؤها هي فئة فرعية من جركالكولاتور، ويتم تخزين البايتود التي تنتجها تجميعها داخل الكائن جاسبيريبورت. يتم تحميل هذا البتكود في الوقت ملء التقرير والطبقة الناتجة هو مثيل للحصول على كائن آلة حاسبة اللازمة لتقييم التعبير. التعبيرات الشرطية لا يدعم جاسبيريبورتس عبارات إف-إلس عند تحديد تعبيرات متغيرة. بدلا من ذلك، يمكنك استخدام عوامل التشغيل الثلاثية. . . يمكن تداخل هذا المشغل داخل تعبير جافا للحصول على الإخراج المطلوب بناء على شروط متعددة. مثال للتعبير المشروط في تقرير يتيح تعديل نموذج التقرير الحالي (تصاميم تقرير الفصل) وإضافة تعبير شرطي لبلد الحقل. نموذج التقرير المنقح (jasperreporttemplate. jrxml) هو كما يلي. حفظه إلى C: تولسجاسبيريبورتس-5.0.1test الدليل ناقص رموز جافا لملء التقرير هي كما يلي. محتويات الملف C: toolsjasperreports-5.0.1testsrccomtutorialspointJasperReportFill. java هي ناقص محتويات ملف بوجو C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBean. java هي ناقص سوف نقوم بإضافة سجل جديد مع حقل البلد فارغة في فول لدينا جافا قائمة. محتويات الملف C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBeanList. java هي ناقص تقرير الجيل سوف نقوم بتجميع وتنفيذ الملف أعلاه باستخدام لدينا العادية عملية بناء أنت. محتويات الملف build. xml (المحفوظة تحت الدليل C: تولسجاسبيريبورتس-5.0.1test) مبينة أدناه. يتم استيراد ملف الاستيراد - baseBuild. xml من فصل إعداد البيئة ويجب أن توضع في نفس الدليل مثل build. xml. بعد ذلك، يتيح فتح نافذة سطر الأوامر والذهاب إلى الدليل حيث يتم إنشاء build. xml. وأخيرا، تنفيذ الأمر النمل - Dmain الطبقة com. tutorialspoint. JasperReportFill (فيوفولريبورت هو الهدف الافتراضي) كما ناقص ونتيجة لتجميع أعلاه، يفتح نافذة جاسرفيور كما هو مبين في الشاشة أدناه ناقص هنا، يمكننا أن نرى، في السجل الأخير، لم نكن قد مررنا أي بيانات عن البلد الميداني، حيث لا يتم طبع نو كانتري. متغيرات التقرير متغيرات التقرير هي عناصر خاصة مبنية على أعلى تعبير التقرير. تقرير متغيرات تبسيط المهام التالية ناقص تعبيرات التقرير، والتي تستخدم بكثافة في قالب التقرير. يمكن التعبير عن هذه التعبيرات مرة واحدة فقط باستخدام متغيرات التقرير. يمكن للمتغيرات تقرير إجراء حسابات مختلفة استنادا إلى قيم التعبيرات المقابلة مثل عدد، مجموع، متوسط، أدنى، أعلى، التباين، الخ. إذا تم تعريف المتغيرات في تصميم التقرير، ثم يمكن الرجوع إليها من قبل متغيرات جديدة في التعبيرات. وبالتالي، فإن الترتيب الذي يتم فيه الإعلان عن المتغيرات في تصميم التقرير مهم. إعلان متغير إعلان متغير هو كما يلي ناقص كما هو موضح أعلاه، يحتوي عنصر لتفاريابلغت عدد من الصفات. يتم تلخيص هذه السمات أدناه ناقص سمة الاسم مماثلة للمعلمات والحقول. سمة اسم عنصر لتفاريابلغت إلزامية. وهو يسمح بالإشارة إلى المتغير حسب اسمه المعلن في تعبيرات التقرير. سمة الفئة السمة كلاس إلزامية أيضا التي تحدد اسم الفئة لقيم المتغير. القيمة الافتراضية هي java. lang. String. ويمكن تغيير هذا إلى أي فئة متوفرة في كلاسباث، سواء في وقت تجميع التقرير ووقت ملء التقرير. المحرك يعتني نوع الصب في التعبير عن التعبيرات التي يستخدم رمز V، وبالتالي لا يتطلب صب نوع اليدوي. الحساب تحدد هذه السمة ناقص الحساب المطلوب إجراؤه على المتغير عند ملء التقرير. تصف الأقسام الفرعية التالية كافة القيم المحتملة لخاصية حساب حساب عنصر لتفاريابليغت. متوسط ناقص القيمة المتغيرة هي متوسط كل قيمة غير فارغة للتعبير المتغير. صالح للمتغيرات الرقمية فقط. كونت ناقص القيمة المتغيرة هي عدد الحالات غير الخالية من تعبير المتغير. ناقص الأول قيمة المتغير هي قيمة المثيل الأول للتعبير المتغير. يتم تجاهل القيم اللاحقة. أعلى ناقص القيمة المتغيرة هي أعلى قيمة للتعبير المتغير. الأدنى ناقص القيمة المتغيرة هي أدنى قيمة للتعبير المتغير في التقرير. لا شيء ناقص لا يتم إجراء حسابات على المتغير. ستانداردديفياتيون ناقص القيمة المتغيرة هي الانحراف المعياري لجميع القيم غير الفارغة التي تطابق تعبير التقرير. صالح للمتغيرات الرقمية فقط. سوم ناقص القيمة المتغيرة هي مجموع كل القيم غير الخالية التي يتم إرجاعها بواسطة تعبير التقرير. النظام ناقص القيمة المتغيرة هي حساب مخصص (حساب قيمة هذا المتغير بنفسك، باستخدام وظيفة سكريبتليتس من جاسبيريبورتس). الفرق ناقص القيمة المتغيرة هي التباين لجميع القيم غير الخالية التي يتم إرجاعها بواسطة تقييم متغيرات التقرير. إنكريمنتر فاكتوريكلاس تحدد هذه السمة الفئة المستخدمة لحساب قيمة المتغير عند ملء السجل الحالي على التقرير. القيمة الافتراضية ستكون أي فئة تنفيذ net. sf. jasperreports. engine. fill. JRIncrementerFactory. سيتم استخدام فئة المصنع بواسطة محرك لتكوين كائنات زيادة في وقت التشغيل اعتمادا على السمة حساب تعيين للمتغير. إنكريمنتيب يحدد هذا الوقت لإعادة حساب قيمة المتغير. تستخدم هذه السمة القيم، على النحو التالي ناقص العمود ناقص يتم إعادة حساب قيمة المتغير في نهاية كل عمود. المجموعة ناقص يتم إعادة حساب القيمة المتغيرة عندما يتم تحديد المجموعة بواسطة تغييرات المجموعة الإضافية. نون ناقص يتم إعادة حساب قيمة المتغير مع كل سجل. الصفحة ناقص يتم إعادة حساب قيمة المتغير في نهاية كل صفحة. تقرير ناقص يتم إعادة حساب القيمة المتغيرة مرة واحدة، في نهاية التقرير. إنكريمنتغروب يحدد هذا اسم المجموعة التي يتم إعادة حساب قيمة المتغير عندما يكون إنكريمنتيب هو مجموعة. هذا يأخذ اسم أي مجموعة أعلن في قالب تقرير جركسمل. هذا يحدد متى يتم إعادة تعيين قيمة متغير. تستخدم هذه السمة القيم، على النحو التالي ناقص العمود ناقص يتم إعادة تعيين قيمة المتغير في بداية كل عمود. المجموعة ناقص يتم إعادة تعيين قيمة المتغير عندما يتم تحديد المجموعة بواسطة التغييرات إنكريمنتغروب. نون ناقص لا يتم إعادة تعيين قيمة المتغير أبدا. صفحة ناقص يتم إعادة تعيين قيمة المتغير في بداية كل صفحة. التقرير ناقص يتم إعادة تعيين قيمة المتغير مرة واحدة فقط، في بداية التقرير. ريستغروب يحدد هذا اسم المجموعة التي يتم إعادة تعيين قيمة المتغير عندما ريسيتيب هو المجموعة. قيم هذه السمة ستكون اسم أي مجموعة تم الإعلان عنها في قالب تقرير جركسمل. متغيرات تقرير مضمن هناك بعض متغيرات النظام المضمنة، جاهزة للاستخدام في التعبيرات، على النحو التالي ناقص اسم المتغير ووصف هذه المتغيرات القيمة هو رقم الصفحة الحالية. ويمكن استخدامه لعرض كل من رقم الصفحة الحالية والعدد الإجمالي للصفحات باستخدام ميزة خاصة من عناصر حقل النص جاسبيريبورتس، السمة ريسترايتمتيمي. اسم هذا المتغير مشتق من اسم المجموعة التي يتوافق معها، مع اضافته كونت تسلسل. يحتوي هذا المتغير على عدد السجلات في المجموعة الحالية. يتيح إضافة متغير (كونتنومبر) إلى قالب التقرير الحالي (تصاميم تقرير الفصل). سنقوم بادئة العد إلى كل سجل. نموذج التقرير المنقح (jasperreporttemplate. jrxml) هو كما يلي. حفظه إلى C: تولسجاسبيريبورتس-5.0.1test ديركتوري ناقص رموز جافا لملء التقرير لا تزال دون تغيير. محتويات الملف C: toolsjasperreports-5.0.1testsrccomtutorialspointJasperReportFill. java هي كما هو موضح أدناه ناقص محتويات ملف بوجو C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBean. java هي كما هو موضح أدناه ناقص محتويات الملف C: تولسجاسبريبورتس-5.0. 1testsrccomtutorialspointDataBeanList. java هي كما هو مبين أدناه ناقص جيل التقرير سوف نقوم بتجميع وتنفيذ الملف أعلاه باستخدام لدينا العادية عملية بناء أنت. محتويات الملف build. xml (المحفوظة تحت الدليل C: تولسجاسبيريبورتس-5.0.1test) كما هو موضح أدناه. يتم استيراد ملف الاستيراد - baseBuild. xml من "إعداد البيئة الفصل" ويجب أن توضع في نفس الدليل مثل build. xml. بعد ذلك، يتيح فتح نافذة سطر الأوامر والذهاب إلى الدليل حيث يتم إنشاء build. xml. وأخيرا، تنفيذ الأمر النملة - Dmain-classcom. tutorialspoint. JasperReportFill (فيفولريبورت هو الهدف الافتراضي) كما ناقص ونتيجة لتجميع أعلاه، يفتح نافذة جاسرفيور كما هو الحال في الشاشة أدناه ناقص هنا، نرى أن العد مسبوقة لكل سجل. أقسام التقرير ناقشنا بنية نموذج تقرير بسيط في الفصل الشروع في العمل. على غرار ذلك، جاسبيريبورتس هيكلة قالب التقرير إلى أقسام متعددة. المقاطع هي أجزاء من التقرير لها ارتفاع محدد ويمكن أن تحتوي على كائنات التقرير مثل خطوط أو مستطيلات أو صور أو حقول نص. محرك التقرير يتكرر من خلال السجلات الافتراضية لمصدر بيانات التقرير الموردة، في وقت ملء التقرير. اعتمادا على كل أقسام السلوك المحدد، المحرك ثم يجعل كل قسم التقرير عند الاقتضاء. على سبيل المثال، يتم عرض قسم التفاصيل لكل سجل في مصدر البيانات. عند حدوث فواصل صفحات، يتم عرض رأس الصفحة وأقسام تذييل الصفحة حسب الحاجة. في جاسبيريبورتس، وتسمى أقسام المصطلحات والتقرير أيضا باسم نطاقات التقرير. وتتألف المقاطع من عصابة واحدة أو أكثر. وتملأ هذه الأقسام مرارا وتكرارا في وقت توليد التقارير وتعد الوثيقة النهائية. الأقسام الرئيسية يحتوي قالب التقرير في جاسبيريبورتس على الأقسام الرئيسية التالية ناقص يلخص الجدول التالي كل قسم من الأقسام ناقص ارتفاع القسم يحدد الارتفاع بالبكسل لهذا القسم بالذات وهو مهم جدا في تصميم التقرير العام. برينت عند التعبير A تعبير منطقي يحدد ما إذا كان يجب طباعة القسم أم لا. سبليت ألود علامة تشير إلى ما إذا كان القسم مسموحا بتقسيمه عندما لا يتناسب مع الصفحة الحالية. إذا كان صحيحا، سيتم نقل القسم إلى الصفحة التالية. لاحظ أنه في حالة، لا تناسب القسم على الصفحة التالية، ثم سيتم تقسيم القسم بغض النظر عن قيمة الأعلام. سبليتيب يمكن أن تأخذ القيم التالية ناقص سبليتيبستريتش: الانشقاقات امتدت المحتوى. إذا كان القسم يمتد على الصفحة الحالية (إذا كانت المساحة المتاحة أقل من الارتفاع المعلن)، يسمح للمنطقة المضافة إلى الارتفاع الأصلي بالتقسيم على الصفحة التالية. سبليتيببريفنت: منع الانقسام في المحاولة الأولى. إذا كان القسم لا يصلح على الصفحة التالية، يحدث الانقسام بشكل طبيعي، كما منع انقسام الفرقة فعالة فقط على محاولة الانقسام الأولى. سبليتيبمتوسط: انقسم على الفور. يسمح الفرقة لتقسيم أي مكان باستثناء أعلاه، عنصره العلوي. لإظهار كل قسم، يتيح كتابة نموذج التقرير (jasperreporttemplate. jrxml). حفظ هذا الملف إلى C: تولسجاسبيريبورتس-5.0.1test الدليل. في هذا الملف، سنعرض نصا في كل من الأقسام (ناقشنا أعلاه). محتويات الملف كما هو موضح أدناه ناقص رمز جافا لملء وتوليد التقرير هو أدناه. يتيح حفظ هذا الملف JasperReportFill. java إلى C: تولسجاسبيريبورتس-5.0.1testsrccomtutorialspoint الدليل. هنا، نستخدم مثيل جريمبتيداتاسورس عند ملء التقارير لمحاكاة مصدر بيانات مع سجل واحد فيه، ولكن مع كل الحقول في هذا السجل المفرد نول. إنشاء التقرير سوف نقوم بتجميع وتنفيذ الملف أعلاه باستخدام لدينا العادية عملية بناء أنت. محتويات ملف build. xml (المحفوظة تحت الدليل C: تولسجاسبيريبورتس-5.0.1test) هي على النحو التالي. يتم استيراد ملف الاستيراد - baseBuild. xml من إعداد البيئة الفصل ويجب أن توضع في نفس الدليل مثل build. xml. بعد ذلك، يتيح فتح نافذة سطر الأوامر والذهاب إلى الدليل حيث يتم إنشاء build. xml. وأخيرا، تنفيذ الأمر النملة - Dmain-classcom. tutorialspoint. JasperReportFill (فيفولريبورت هو الهدف الافتراضي) كما يلي ناقص ونتيجة لتجميع أعلاه، يفتح نافذة جاسرفيور كما هو الحال في الشاشة أدناه ناقص هنا، يمكننا أن نرى في كل من 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
No comments:
Post a Comment