By: Ingmar Stein - ingmarstein

Counting non-numeric values

2002-04-11 02:31

Hi all,

JasperReports seems not to support the case variable type != expression type. For example,

it should be possible to use the count function

to count non-numeric values like in the following

statement:

<variable name="mailCount" class="java.lang.Long" resetType="Report" calculation="Count">

<variableExpression>$F{mailQueueName}</variableExpression>

</variable>

where mailQueueName is a String value.

JasperReports produces invalid casts in the

generated class file as it uses the expression

type as the variable type. However, what I expect

it to do is determining the result type of the

applied calculation.

Cheers,

Ingmar

By: Ingmar Stein - ingmarstein

RE: Counting non-numeric values

2002-04-11 07:47

I implemented a workaround by removing the cast in generateMethod (JRClassGenerator.java):

- " value = (" + jrExpression.getValueClass().getName() + ")("

+ "("

and by not forcing the expression to have a numeric value in calculateVariable (JRCalculator.java):

case JRVariable.CALCULATION_COUNT :

{

Number value = (Number)jrVariable.getValue();

if (value == null || jrVariable.isInitialized())

{

value = new Double(0);

}

Number newValue;

if (expressionValue == null)

{

newValue = value;

}

else

{

newValue = new Double(value.doubleValue() + 1);

}

retValue = convertToVariableClass(jrVariable, newValue);

break;

}

Ingmar

By: Corey Puffalt - yeroc

RE: Counting non-numeric values

2002-10-04 09:07

I just ran into this problem myself with 0.4.0. Is there any chance of getting this patch applied?

It would be greatly appreciated. I don't see any reason why it shouldn't be able to count non-numeric fields?

By: Corey Puffalt - yeroc

RE: Counting non-numeric values

2002-10-04 09:09

I just ran into this problem myself with 0.4.0. Is there any chance of getting this patch applied?

It would be greatly appreciated. I don't see any reason why it shouldn't be able to count non-numeric fields?

By: Corey Puffalt - yeroc

RE: Counting non-numeric values

2002-10-04 09:07

I just ran into this problem myself with 0.4.0. Is there any chance of getting this patch applied?

It would be greatly appreciated. I don't see any reason why it shouldn't be able to count non-numeric fields?

By: Teodor Danciu - teodord

RE: Counting non-numeric values

2002-10-09 01:14

Hi,

This will be finally fixed in the 0.4.2 version.

Until then, you could make a trick to get over it.

In fact, count variables count the non null values of their

corresponding expression.

You could still count non numeric expressions by wrapping them and converting their value to numeric like this:

<variable name="NotNullNamesCount" class="java.lang.Integer" calculation="Count">

<variableExpression>($F{Name} == null ? null : new Integer(1))</variableExpression>

</variable>

This variable counts for the not null values of a String field

called Name.

I have not tested this, but it should work.

Thank you,

Teodor

By: Teodor Danciu - teodord

RE: Counting non-numeric values

2002-10-15 14:12

Hi,

Counting for non-numeric values is now possible

in the 0.4.2 version.

Thank you,

Teodor

Counting non-numeric values

2002-04-11 02:31

Hi all,

JasperReports seems not to support the case variable type != expression type. For example,

it should be possible to use the count function

to count non-numeric values like in the following

statement:

<variable name="mailCount" class="java.lang.Long" resetType="Report" calculation="Count">

<variableExpression>$F{mailQueueName}</variableExpression>

</variable>

where mailQueueName is a String value.

JasperReports produces invalid casts in the

generated class file as it uses the expression

type as the variable type. However, what I expect

it to do is determining the result type of the

applied calculation.

Cheers,

Ingmar

By: Ingmar Stein - ingmarstein

RE: Counting non-numeric values

2002-04-11 07:47

I implemented a workaround by removing the cast in generateMethod (JRClassGenerator.java):

- " value = (" + jrExpression.getValueClass().getName() + ")("

+ "("

and by not forcing the expression to have a numeric value in calculateVariable (JRCalculator.java):

case JRVariable.CALCULATION_COUNT :

{

Number value = (Number)jrVariable.getValue();

if (value == null || jrVariable.isInitialized())

{

value = new Double(0);

}

Number newValue;

if (expressionValue == null)

{

newValue = value;

}

else

{

newValue = new Double(value.doubleValue() + 1);

}

retValue = convertToVariableClass(jrVariable, newValue);

break;

}

Ingmar

By: Corey Puffalt - yeroc

RE: Counting non-numeric values

2002-10-04 09:07

I just ran into this problem myself with 0.4.0. Is there any chance of getting this patch applied?

It would be greatly appreciated. I don't see any reason why it shouldn't be able to count non-numeric fields?

By: Corey Puffalt - yeroc

RE: Counting non-numeric values

2002-10-04 09:09

I just ran into this problem myself with 0.4.0. Is there any chance of getting this patch applied?

It would be greatly appreciated. I don't see any reason why it shouldn't be able to count non-numeric fields?

By: Corey Puffalt - yeroc

RE: Counting non-numeric values

2002-10-04 09:07

I just ran into this problem myself with 0.4.0. Is there any chance of getting this patch applied?

It would be greatly appreciated. I don't see any reason why it shouldn't be able to count non-numeric fields?

By: Teodor Danciu - teodord

RE: Counting non-numeric values

2002-10-09 01:14

Hi,

This will be finally fixed in the 0.4.2 version.

Until then, you could make a trick to get over it.

In fact, count variables count the non null values of their

corresponding expression.

You could still count non numeric expressions by wrapping them and converting their value to numeric like this:

<variable name="NotNullNamesCount" class="java.lang.Integer" calculation="Count">

<variableExpression>($F{Name} == null ? null : new Integer(1))</variableExpression>

</variable>

This variable counts for the not null values of a String field

called Name.

I have not tested this, but it should work.

Thank you,

Teodor

By: Teodor Danciu - teodord

RE: Counting non-numeric values

2002-10-15 14:12

Hi,

Counting for non-numeric values is now possible

in the 0.4.2 version.

Thank you,

Teodor

## 0 Answers:

*No answers yet*