PDA

View Full Version : problem with function



Anonymous
07-09-2002, 06:20 AM
Hi
I have created a function wich set a value of a field related to a another field.

I don't understand why the report first invoke getValue() method
and after invoke the itemsAdvanced(ReportEvent evt) method

Anonymous
07-09-2002, 09:03 AM
Hi,

I also thought so, so have a look at the cvs, this issue is fixed there. If you don't have access to the cvs, you may use this link
to download the changed ReportState.java file:

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/jfreereport/jfreereport/source/com/jrefinery/report/ReportState.java?rev=1.16

Have more fun,
said Thomas

Anonymous
07-09-2002, 10:09 AM
Hi,
I have downloaded the file and i have updated the package, but the result is the same:

I post my simple class:

import com.jrefinery.report.*;
import com.jrefinery.report.function.*;
import com.jrefinery.report.event.ReportEvent;

public class IfFunction extends AbstractFunction{
public IfFunction() {}

public IfFunction(String name){
setName(name);
}


public void itemsAdvanced(ReportEvent evt){

String str = evt.getReport().getItemBand().getElement("hidden np_proeu").getValue()+"";

if (str.equals("1")){
value = evt.getReport().getItemBand().getElement("hidden np_int" ).getValue()+"";
}else{
value ="E";
}
}

public Object getValue(){
return value;
}

private Object value;
private JFreeReport report;
int i;
}



The XML File
...
<items height="25" fontstyle="plain" fontsize="6">
<string-field name="hidden np_proeu" fontsize = "0" x="0" y="0" width="0" height="0" fieldname="np_proeu"/>
<string-field name="hidden np_int" fontsize = "0" x="0" y="0" width="0" height="0" fieldname="np_int"/>

<string-function name = "field Int2" function = "Int.If" x = "485" y="25" width = "10" height="10" alignment="left" fontsize="6" />
...
<functions>
<function name="Int.If" class="IfFunction"/>
</functions>



The result of the function is correct, but it start from the second item because the getValue() method is invoked first than itemsAdvanced(ReportEvent evt).

Where is my error???

Anonymous
07-09-2002, 03:35 PM
Hi,

this is simple. Functions are evaluated before the fields are filled. The functions values are then added to to function-fields and the whole thing is printed.

The current way of reading data is to use the tablemodel to access the data. Have a look at ItemSumFunction to see a working example.

Before you say it: Yes, this is weired and by far not intuitive. The whole filling concept needs a facelifting, yte another thing to work on ... ;)

Have more fun,
said Thomas