PDA

View Full Version : grouping



Anonymous
07-18-2002, 01:02 AM
1>I am facing a problem in grouping. I have to get the report in the following manner---->

report header
Category1 header
type11 header
data11----------------
type11 footer
type12 header
data12---------------
type12 footer
Category1 footer

Category2 header
type21 header
data21----------------
type21 footer
type22 header
data22---------------
type22 footer
Category2 footer
report footer

But I am getting like --->

report header
category1 header
type11header
data11----------------
data12----------------
data21----------------
data22----------------
type11footer
category1 footer
report footer

---and other headers and footers are missing
we have defiend all gropus and functions in the xml. We r constructing default table model dynamically depending on the data.

2>Is it necessary to use Comparable interface and sort the list in the table using comparable?

Anonymous
07-18-2002, 05:25 AM
You should probably post the XML you are using to define the groups. That will make it easier for me (or someone else) to spot the problem.

It is necessary to sort your data before passing it to JFreeReport, since JFreeReport doesn't perform any sorting for you.

Regards,

DG.

Anonymous
07-18-2002, 08:10 AM
<?xml version="1.0" encoding="iso-8859-1"?>
<report name="Test Report" width="0" height="0">
<reportheader height="44" fontname="SansSerif" >

<label name="labelrh1" x="0" y="0" width="0" height="20" fontsize="10" alignment="center">DELHI TRANSPORT CORPORATION</label>

<label name="labelrh2" x="0" y="24" width="0" height="15" fontsize="15" alignment="center">DAY SCROLL (COUNTER/CATEGORYWISE DETAILS)</label>

<label name="labelrh3" x="0" y="40" width="0" height="10" fontsize="10" alignment="center"></label>

</reportheader>
<reportfooter height="24" fontname="SansSerif" fontstyle="bold" fontsize="10">

<label name="labelrf1" x="0" y="55" width="0" height="20" alignment="center">END OF REPORT</label>


</reportfooter>
<pageheader height="32" firstpage="true" fontname="Serif" fontsize="6">

<line name="lineph1" x1="0" y1="30" x2="0" y2="30" weight="0.5"></line>

<label name="labelph1" x="3" y="0" width="48" height="20" alignment="left">Trn Type</label>

<label name="labelph2" x="51" y="0" width="70" height="20" alignment="left">ID No</label>

<label name="labelph3" x="118" y="0" width="50" height="20" alignment="right">Old Tkt</label>

<label name="labelph4" x="163" y="0" width="50" height="20" alignment="right">New Tkt</label>

<label name="labelph5" x="213" y="0" width="20" height="20" alignment="right">Prd</label>

<label name="labelph6" x="233" y="0" width="55" height="20" alignment="right">V From</label>

<label name="labelph7" x="288" y="0" width="45" height="20" alignment="right">V Till</label>

<label name="labelph8" x="343" y="0" width="40" height="20" alignment="right">Amt</label>

<label name="labelph9" x="380" y="0" width="40" height="20" alignment="right">S Ch</label>

<label name="labelph10" x="420" y="0" width="40" height="20" alignment="right">RA Ch</label>

<line name="lineph2" x1="0" y1="7" x2="0" y2="7" weight="0.5"></line>


</pageheader>
<pagefooter height="45" firstpage="true" lastpage="true" fontname="Serif" fontstyle="italic" fontsize="9">

<line name="linepf2" x1="0" y1="22" x2="0" y2="22" weight="0.5"></line>
<date-function name="date1" width="200" function="Date" format="d-MMM-yyyy" x="0" y="25" height="18" alignment="left"></date-function>
<number-function name="pagenum1" function="PageNumber" format="Page 0" x="0" y="25" width="0" height="18" alignment="right"></number-function>

</pagefooter>
<groups>
<group name="ISS_COUNTER">
<groupheader height="22" fontname="Arial" fonstyle="bold" fontsize="9">
<label name="Labelgh11" x="3" y="1" width="76" height="8" alignment="left">Shift:</label>
<number-field name="shift" x="96" y="1" width="76" height="9" alignment="left" format="###0">ISS_SHIFT</number-field>
<label name="Labelgh12" x="3" y="10" width="76" height="8" alignment="left">Counter No:</label>
<number-field name="counter" x="96" y="10" width="76" height="9" alignment="left" format="###0">ISS_COUNTER</number-field>
<label name="Labelgh13" x="300" y="1" width="80" height="8" alignment="left">Date of isuue :</label>
<date-field name="date2" format="d-MMM-yyyy" x="385" y="1" width="76" height="8" alignment="left">ISS_DT</date-field>
</groupheader>
<groupfooter height="12" fontname="Arial" fontstyle="bold" fontsize="9">
<label name="Labelgf21" x="0" y="0" width="468" height="12" alignment="left" fontname="Arial" fonstyle="bold" fontsize="9">Counter Total:</label>
<line name="linegf21" x1="0" y1="2" x2="0" y2="2" weight="0.5"></line>
<number-function name="totalcountercsum" function="CSum" format="#,##0.00" x="333" y="0" width="50" height="12" alignment="right"></number-function>
<number-function name="totalcounterssum" function="SSum" format="#,##0.00" x="380" y="0" width="40" height="12" alignment="right"></number-function>
<number-function name="totalcounterrsum" function="RSum" format="#,##0.00" x="420" y="0" width="40" height="12" alignment="right"></number-function>
<line name="linegf22" x1="0" y1="22" x2="0" y2="22" weight="0.5"></line>
</groupfooter>

<!--<fields>
<field>ISS_SHIFT</field>
<field>ISS_COUNTER</field>
<field>ISS_DT</field>
</fields>-->

</group>
<group name="CATEGORY">
<groupheader height="12" fontname="Arial" fonstyle="bold" fontsize="9">
<label name="Labelgh21" x="3" y="1" width="76" height="8" alignment="left">Category:</label>
<string-field name="category" x="96" y="1" width="76" height="9" alignment="left">CATEGORY</string-field>
</groupheader>
<groupfooter height="14" fontname="Arial" fontstyle="bold" fontsize="9">
<line name="linegf11" x1="0" y1="2" x2="0" y2="2" weight="0.5"></line>
<label name="Labelgf11" x="0" y="0" width="468" height="12" alignment="left" fontname="Arial" fonstyle="bold" fontsize="9">Category Total:</label>
<number-function name="totalcatcsum" function="CatCSum" format="#,##0.00" x="333" y="0" width="50" height="12" alignment="right"></number-function>
<number-function name="totalcatssum" function="CatSSum" format="#,##0.00" x="380" y="0" width="40" height="12" alignment="right"></number-function>
<number-function name="totalcatrsum" function="CatRSum" format="#,##0.00" x="420" y="0" width="40" height="12" alignment="right"></number-function>
</groupfooter>
<!--<fields>
<field>CATEGORY</field>
</fields>-->

</group>
<group name="PASSTYPE">
<groupheader height="12" fontname="Arial" fonstyle="bold" fontsize="9">
<label name="Labelgh31" x="3" y="1" width="76" height="8" alignment="left">Type:</label>
<string-field name="pass type" x="96" y="1" width="76" height="9" alignment="left">PASSTYPE</string-field>
</groupheader>
<groupfooter height="14" fontname="Arial" fontstyle="bold" fontsize="9">
<label name="Labelgf31" x="0" y="0" width="468" height="12" alignment="left" fontname="Arial" fonstyle="bold" fontsize="9">PassType Total:</label>
<number-function name="totaltcsum" function="TCSum" format="#,##0.00" x="333" y="0" width="50" height="12" alignment="right"></number-function>
<number-function name="totaltssum" function="TSSum" format="#,##0.00" x="380" y="0" width="40" height="12" alignment="right"></number-function>
<number-function name="totaltrsum" function="TRSum" format="#,##0.00" x="420" y="0" width="40" height="12" alignment="right"></number-function>
<line name="linegf31" x1="0" y1="2" x2="0" y2="2" weight="0.5"></line>

</groupfooter>
<!--<fields>
<field>PASSTYPE</field>
</fields>-->

</group>
</groups>
<items height="10" fontname="Arial" fontstyle="plain" fontsize="6">
<string-field name="IDCARD" x="3" y="0" width="45" height="8" alignment="left">IDCARD</string-field>

<string-field name="ID_CARD_NO" x="48" y="0" width="65" height="8" alignment="left">ID_CARD_NO</string-field>

<number-field name="Old Ticket" x="113" y="0" width="50" height="8" alignment="right" format="###0">Old Ticket</number-field>

<number-field name="New Ticket" x="163" y="0" width="50" height="8" alignment="right" format="######0">New Ticket</number-field>

<number-field name="PER" x="213" y="0" width="20" height="8" alignment="right" format="######0">PER</number-field>

<date-field name="VALFRM" x="233" y="0" width="55" height="8" alignment="right" format="dd-MMM-yy">VALFRM</date-field>

<date-field name="VALID_TILL" x="288" y="0" width="55" height="8" alignment="right" format="dd-MMM-yy">VALID_TILL</date-field>

<number-field name="AMT" x="343" y="0" width="40" height="8" alignment="right" format="#,##0.00">AMT</number-field>

<number-field name="SRVC_CHRGE" x="380" y="0" width="40" height="8" alignment="right" format="#,##0.00">SRVC_CHRGE</number-field>

<number-field name="RECHARGE" x="420" y="0" width="40" height="8" alignment="right" format="#,##0.00">RECHARGE</number-field>
</items>

<functions>

<function name="Date" class="com.jrefinery.report.function.ReportPropertyFunction">Report Date</function>
<function name="PageNumber" class="com.jrefinery.report.function.PageFunction">Name</function>
<function name="CSum" class="com.jrefinery.report.function.ItemSumFunction">AMT</function>
<function name="SSum" class="com.jrefinery.report.function.ItemSumFunction">SRVC_CHRGE</function>
<function name="RSum" class="com.jrefinery.report.function.ItemSumFunction">RECHARGE</function>
<function name="CatCSum" group="CATEGORY" class="com.jrefinery.report.function.ItemSumFunction">AMT</function>
<function name="CatSSum" group="CATEGORY" class="com.jrefinery.report.function.ItemSumFunction">SRVC_CHRGE</function>
<function name="CatRSum" group="CATEGORY" class="com.jrefinery.report.function.ItemSumFunction">RECHARGE</function>
<function name="TCSum" group="PASSTYPE" class="com.jrefinery.report.function.ItemSumFunction">AMT</function>
<function name="TSSum" group="PASSTYPE" class="com.jrefinery.report.function.ItemSumFunction">SRVC_CHRGE</function>
<function name="TRSum" group="PASSTYPE" class="com.jrefinery.report.function.ItemSumFunction">RECHARGE</function>

</functions>

</report>

Anonymous
07-18-2002, 11:50 AM
Hi Mahesh,

I'm not 100% sure of the reason why, but when you have nested groups, in the sub-groups you need to repeat the names of the fields in the parent group.

Report 2 in the demo is an example, here I've stripped out the headers and footers to show more clearly how the group fields are defined:


<groups>


<group name="Letter Group">





<fields>
<field>Letter</field>
</fields>

</group>


<group name="Color Group">





<fields>
<field>Letter</field>
<field>Color</field>
</fields>

</group>

</groups>

See how the Color group, which is a subgroup within the Letter group, defines Letter and Color as it's group fields.

I think that is what you are missing in your report definition. You have CATEGORY for the field in your first group, and I think you need CATEGORY and PASSTYPE as the fields in your second group.

Regards,

DG.

Anonymous
07-18-2002, 02:35 PM
Hi,

nested groups require the complete key, because the groups are ordered internally by those keys. A group is considered more specific the more fields are in the group.

Sub-Groups depend on its parent, but the group list is not able to recognize which group has a higher priority if the complete key is not known.

Internally the group changes when one or more fields change. So for your example, Group "Color Group" is triggered when either "Letter" or "Color" change.

JFreeReports report engine requires a strict hierachy of groups where every sub-group depends fully on its parent.

So if you want to group like:

1. * ISS_COUNTER
1.1 * CATEGORY
1.1.1 * PASSTYPE

you have to declare your groups like:


<group name="ISS_COUNTER">
<fields>
<field>ISS_SHIFT</field>
<field>ISS_COUNTER</field>
<field>ISS_DT</field>
</fields>
</group>


<group name="CATEGORY">
<fields>
<field>ISS_SHIFT</field>
<field>ISS_COUNTER</field>
<field>ISS_DT</field>
<field>CATEGORY</field>
</fields>
</group>


<group name="PASSTYPE">
<fields>
<field>ISS_SHIFT</field>
<field>ISS_COUNTER</field>
<field>ISS_DT</field>
<field>CATEGORY</field>
<field>PASSTYPE</field>
</fields>
</group>


Have more fun,
said Thomas

Anonymous
01-13-2003, 08:41 AM
Hi All.

I am producing a report which has several groups in it. Each group has a groupheader AND groupfooter. The groupheader's 'title' is taken from the 'Level' field in my tablemodel (i.e. <string-field x="0" y="3" width="300" alignment="left" fieldname="Level"></string-field>.

As the report is being produced, I want to check the 'title' of each group's groupheader. If the groupheader's title="No Description", then I want to set the groupheader + groupfooter band to INVISIBLE.

Question is: how do I check what the value of the groupheader is while creating the report? I know how to make a band invisible....but I don't know how to access and check the value of a groupheader's string-field element.

Anyone have any solutions or suggestions?

thanks.

-sandra

Anonymous
01-13-2003, 09:46 AM
Hi,

write a ReportFunction, and there in the groupStarted() method set the groupheader/footer to invisible before it is printed.

To access fields from the tablemodel or from a function, use the DataRow.


public void groupStarted (ReportEvent event)
{
int groupIndex = event.getState().getCurrentGroupIndex();
Group currentGroup = event.getReport().getGroup(groupIndex);

// don't modify other groups
if (currentGroup.getName().equals("the name of the group header's group") == false)
{
return;
}

// all bands should be visible by default
boolean visible = true;
String level = (String) event.getDataRow().get("Level");
if (level != null && level.equals("No Description"))
{
// only hide the flag if level exists and has the value "No Description"
visible = false;
}

currentGroup.getHeader().setVisible(visible);
currentGroup.getFooter().setVisible(visible);
}


This method-snipplet will hide the header and footer of the specified group if the field level has the value "No Description".

SImply put this into a ReportFunction and it should work ...

Have more fun,
said Thomas

Anonymous
01-16-2003, 06:17 AM
ok Thomas...your coding suggestion worked like a charm! But there's one more thing I'm trying to figure out:

In a report group, I need to change what is displayed in the group's LABEL element at run-time. I've tried the following code (see below) but it doesn't make a difference to the contents of the group's label whatsoever!

****** Start Code ******
public void groupStarted(ReportEvent event) {

int groupIndex = event.getState().getCurrentGroupIndex();
Group currentGroup = event.getReport().getGroup(groupIndex);
String closed = "";

// check if we're currently looking at CLOSED group
if (currentGroup.getName().equals("Closed")) {
closed = (String) event.getDataRow().get("Closed");
}
else {
// do nothing
return;
}


if (closed != null) {
// get handle to group's label
Element n = currentGroup.getHeader().getElement("lblDesc");

if (closed.equals("N") {
n.setLabel("TOTALS");
}
else {
n.setLabel("CLOSED OUT");
}
}
}
****** End Code ******

Any help would be much appreciated!!

-sandra

Anonymous
01-16-2003, 10:27 AM
Hi,

if you need to change the displayed value of an element, then you should not use a Label as element type. Labels ar immutable, and changing the text is possible, but more difficult than just setting the value with a method.

If you want to change the text of an text element, then write a function which returns a string, and in the report definition use a String-Field instead of a label.

The string field is able to query the function, and all you have to do is to write a function that returns the correct value.

Your case does not even need a function, a BSHExpression will do the same job:

<expression name="groupLabelChange" class="com.jrefinery.report.function.BSHExpression">
<properties>
<property name="expression">

// this is the main method of the bsh-expression
Object getValue ()
{
String closed = String.valueOf (dataRow().get("Closed"));
if (closed.equals("N")
{
return "TOTALS";
}
else
{
return "CLOSED OUT";
}
}

</property>
</properties>

And within the group header definition, change the label definiton into a string-field definition:

<string-field field="groupLabelChange" ... />

Whenever the field is printed, the assigned expression is queried, and if the field "Closed" is not "N", the label changes to "CLOSED OUT".

As the expression is connected with the field in the group header, the expression's calculated value will only influence this element, and the element itself will only be printed when it's group is active.

Have more fun,
said Thomas

Anonymous
01-20-2003, 11:30 AM
OK. I put in your suggestion of using an expression - but when I execute my report, I get the following error message:

java.lang.NoSuchMethodError: bsh.Interpreter.eval(Ljava/io/Reader;)Ljava/lang/Object;
at com.jrefinery.report.function.BSHExpression.initialize(BSHExpression.java:164)
at com.jrefinery.report.ExpressionCollection.add(ExpressionCollection.java:247)
at com.jrefinery.report.JFreeReport.addExpression(JFreeReport.java:496)
at com.jrefinery.report.io.FunctionFactory.endExpression(FunctionFactory.java:334)
at com.jrefinery.report.io.FunctionFactory.endElement(FunctionFactory.java:305)
at com.jrefinery.report.io.ReportDefinitionContentHandler.endElement(ReportDefinitionContentHandler.java:187)
at org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1403)
at org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLValidator.java:1180)
at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1201)
at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:952)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
at com.jrefinery.report.io.ReportGenerator.parseReport(ReportGenerator.java:221)
at com.jrefinery.report.io.ReportGenerator.parseReport(ReportGenerator.java:145)
at com.jrefinery.report.io.ReportGenerator.parseReport(ReportGenerator.java:125)

How can I correct this error?

thanks.
-sandra

Anonymous
01-20-2003, 02:58 PM
Hi,

this sounds like there is no BeanShell (bsh-1.2b6) in your classpath. The beanshell provides the bsh.Interpreter class, and the supplied version does have a method

public Object eval(Reader);

The JFreeReport demo also uses the beanshell-expression, so if you get report1.xml up and running, your installation should be ok.

Have more fun,
said Thomas

Anonymous
01-22-2003, 10:07 AM
Hi.

I put the BeanShell into my classpath, and managed to get report1.xml up and running...but when I tried to run my report this time - I got the following error:

*********
com.jrefinery.report.io.ReportDefinitionException: In file: <Inline eval of: getValue ()
{ String closed=String.valueOf(dataRow().get("Closed"));
if (closed.equals("N")
{ return "TOTALS"; }
else
{ return "CLOSED OUT"; }
}
; > Encountered "return" at line 4, column 3.



at com.jrefinery.report.io.ReportGenerator.parseReport(ReportGenerator.java:235)

at com.jrefinery.report.io.ReportGenerator.parseReport(ReportGenerator.java:145)

at com.jrefinery.report.io.ReportGenerator.parseReport(ReportGenerator.java:125)

at ie.dcs.phs.CouponManager.reports.rptRedemptionPDF.parseReport(rptRedemptionPDF.java:215)

at ie.dcs.phs.CouponManager.reports.rptRedemptionPDF.previewDoc(rptRedemptionPDF.java:99)

at ie.dcs.phs.CouponManager.reports.rptRedemptionPDF.previewReport(rptRedemptionPDF.java:200)

at ie.dcs.phs.CouponManager.reports.IC4Market.previewReport(IC4Market.java:316)

at ie.dcs.phs.CouponManager.reports.IC4Report.previewReportComponent(IC4Report.java:286)

at ie.dcs.phs.CouponManager.reports.IC4Report.main(IC4Report.java:358)

ParentException:com.jrefinery.report.function.FunctionInitializeException: In file: <Inline eval of: getValue ()
{ String closed=String.valueOf(dataRow().get("Closed"));
if (closed.equals("N")
{ return "TOTALS"; }
else
{ return "CLOSED OUT"; }
}
; > Encountered "return" at line 4, column 3.



at com.jrefinery.report.io.FunctionFactory.endExpression(FunctionFactory.java:338)

at com.jrefinery.report.io.FunctionFactory.endElement(FunctionFactory.java:305)

at com.jrefinery.report.io.ReportDefinitionContentHandler.endElement(ReportDefinitionContentHandler.java:187)

at org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1403)

at org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLValidator.java:1180)

at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1201)

at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)

at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:952)

at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)

at com.jrefinery.report.io.ReportGenerator.parseReport(ReportGenerator.java:221)

at com.jrefinery.report.io.ReportGenerator.parseReport(ReportGenerator.java:145)

at com.jrefinery.report.io.ReportGenerator.parseReport(ReportGenerator.java:125)

at ie.dcs.phs.CouponManager.reports.rptRedemptionPDF.parseReport(rptRedemptionPDF.java:215)

at ie.dcs.phs.CouponManager.reports.rptRedemptionPDF.previewDoc(rptRedemptionPDF.java:99)

at ie.dcs.phs.CouponManager.reports.rptRedemptionPDF.previewReport(rptRedemptionPDF.java:200)

at ie.dcs.phs.CouponManager.reports.IC4Market.previewReport(IC4Market.java:316)

at ie.dcs.phs.CouponManager.reports.IC4Report.previewReportComponent(IC4Report.java:286)

at ie.dcs.phs.CouponManager.reports.IC4Report.main(IC4Report.java:358)
*********

What on earth am I doing wrong? Please help...

thanks.
-sandra

Anonymous
01-22-2003, 10:13 AM
Hi,

my fault, I forgot to post the closing bracket for the if-statement. The exception is thrown when the BSH-Code contains syntax-errors.

...
String closed=String.valueOf(dataRow().get("Closed"));
if (closed.equals("N")
{ return "TOTALS"; }
else
{ return "CLOSED OUT"; }
}

The "if" is missing a closing bracket: change this line to

if (closed.equals("N"))

and it should work.

Have more fun,
said Thomas

Anonymous
01-23-2003, 10:21 AM
Hi.

ok - I implemented your change...and the report now works!! :)

There was only one more adjustment I had to make to your code that you gave above - the line:
String closed=String.valueOf(dataRow().get("Closed"));

should actually be:
String closed=String.valueOf(dataRow.get("Closed"));

Thanks a million Thomas for your prompt replies + patience!

-sandra