Jump to content
Changes to the Jaspersoft community edition download ×

Embedding Java in Variable Expression


2004 IR Help

Recommended Posts

By: Steve Jenkings - stevejenks

Embedding Java in Variable Expression

2005-08-05 04:40

Hi,

 

I'm just starting out with Jasper and really like what I've found so far but am having a little trouble with variableExpressions.

 

As I evaluate a group I'd like to create two variables, which are sum types, and display their final values as part of a group footer. However the value of the variables needs to be conditional to an attribute on the object evaluated within a group.

 

So I'd like to create an expression with an embedded if statement something like the one below. I'm not really sure if I can do this but can't find anything in the samples that seems similar to give me an idea of how to achieve this...

 

<variable name="total_1yr_refEntity_cr01_maturity>10" class="java.lang.Double" resetType="Group" resetGroup="ReferenceEntityGroup" calculation="Sum">

<variableExpression>

<![CDATA[if($F{tradeMaturity} > 10) {$F{tradeCr01}} )]]>

</variableExpression>

<initialValueExpression><![CDATA[new Double(0)]]></initialValueExpression>

</variable>

 

 

<variable name="total_1yr_refEntity_cr01_maturity>20" class="java.lang.Double" resetType="Group" resetGroup="ReferenceEntityGroup" calculation="Sum">

<variableExpression>

<![CDATA[if($F{tradeMaturity} > 20) {$F{tradeCr01}} )]]>

</variableExpression>

<initialValueExpression><![CDATA[new Double(0)]]></initialValueExpression>

</variable>

 

 

 

 

 

By: Peter Birchmeier - pbirchmeier

RE: Embedding Java in Variable Expression

2005-08-05 04:57

Hi

 

As far as i know Java statements like if conditions are not possible... A variableExpression must be an Java expression. What you could use in your case:

 

( $F{tradeMaturity}.doubleValue() > 20 ) ? value1 : ( ( $F{tradeMaturity}.doubleValue() > 20 ) ? value2 : value3 )

 

replace doubleValue() by whatever type you need...

 

kind regards,

Peter

 

 

 

 

By: Peter Birchmeier - pbirchmeier

RE: Embedding Java in Variable Expression

2005-08-05 04:59

sorry the expression should be:

 

( $F{tradeMaturity}.doubleValue() > 20 ) ? value1 : ( ( $F{tradeMaturity}.doubleValue() > 10 ) ? value2 : value3 )

 

x1 > 20 >= x2 > 10 >= x3

for x1: value1, x2: value2, x3: value3

 

 

 

 

By: Steve Jenkings - stevejenks

RE: Embedding Java in Variable Expression

2005-08-05 06:11

Yep that did the trick thanks v much.

 

Do you happen to know of the existence of any documentation at this level? I see there once was an e-book but it's now out of date.

 

So far I've worked out the jrxml format by going through the samples but I'm now reaching a point where I need to do things that the samples don't do.

 

 

 

 

By: Peter Birchmeier - pbirchmeier

RE: Embedding Java in Variable Expression

2005-08-05 06:44

I'm not sure if there is a complete tutorial. I learn(ed) by analyzing the examples. Here some ressources:

 

- have a look at the tips&tricks-section: http://jasperreports.sourceforge.net/tips.tricks.html

- http://www.jasperassistant.com/docs/guide/ chapter 6

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...