Jump to content
Changes to the Jaspersoft community edition download ×

Can't get conditionalStyle to work


Recommended Posts

By: C-Box - c-box

Can't get conditionalStyle to work

2006-03-02 02:51

Hi all,

 

I just tried the new "conditionalStyle" in JR 1.2.0....

 

My goal is, to show a textfield in different foregroundcolors depending on a certain parameter (just as a simple test).

 

I created following style in new IReport 1.2.0:

 

<style

name="TestStyle"

fontName="Arial"

fontSize="10"

isBold="false"

isItalic="false"

isUnderline="false"

isStrikeThrough="false"

pdfFontName="Helvetica"

isPdfEmbedded="false"

>

 

<conditionalStyle>

<conditionExpression><![CDATA[new Boolean($P{TestInt}.intValue()>0)]]></conditionExpression>

<style

isDefault="false"

forecolor="#00FF00"

pen="Thin"

fill="Solid"

fontName="Arial"

fontSize="10"

isBold="false"

isItalic="false"

isUnderline="false"

isStrikeThrough="false"

pdfFontName="Helvetica"

isPdfEmbedded="false"

isBlankWhenNull="true"

/>

</conditionalStyle>

<conditionalStyle>

<conditionExpression><![CDATA[new Boolean($P{TestInt}.intValue()<0)]]></conditionExpression>

<style

isDefault="false"

forecolor="#FF0000"

pen="Thin"

fill="Solid"

fontName="Arial"

fontSize="10"

isBold="false"

isItalic="false"

isUnderline="false"

isStrikeThrough="false"

pdfFontName="Helvetica"

isPdfEmbedded="false"

isBlankWhenNull="true"

/>

</conditionalStyle>

</style>

 

 

 

Then I defined a simple Textfield:

 

<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >

<reportElement

style="TestStyle"

mode="Opaque"

x="164"

y="16"

width="367"

height="17"

forecolor="#000000"

backcolor="#FFFFFF"

key="textField-1"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>

<textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single">

<font pdfEncoding ="Cp1252"/>

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA["TestFiedlThatShouldBeColoredDependingAtTheStyleCondition"]]></textFieldExpression>

</textField>

 

 

 

Then I run the report and IReport asks me for my integer paramter.... but I always get a BLACK textfield either if I do put a negative (-1) or a positive (1) value as parameter.....

 

What I'm doing wrong!??!?!?!

 

tia

C-Box

 

 

By: C-Box - c-box

RE: Can't get conditionalStyle to work

2006-03-02 07:26

Hmmmm....

 

I looked at your sample "FirstJasper.jrxml" there the report-element that uses the "OrderIdStyle" has also its own forecolor tag.

 

Should the Style not overwrite the report-element-tags at all if the style(condition) is applied!?!? (So the style overwrites the element properties!?!?)

 

But anyway... its a GREAT FEATURE!!!! (was I the only one who requested it at all!?!?)

 

C-Box

 

 

 

 

By: Lucian Chirita - lucianc

RE: Can't get conditionalStyle to work

2006-03-02 07:52

Are you sure about the FirstJasper.jrxml sample? The element doesn't have a forecolor attribute!

 

Regarding the style attributes priority: when styles were introduced in 1.1.0, style attributes at report element level were intended as a means of locally overriding/customizing a defined style. This was consistent with previous font functionality where a declared report font could be customized locally for a report element that specifies some font attributes of its own.

 

When conditional style functionality was implemented, it was decided that conditions will be declareed at style level and not at element level. This led to the same priority order (element attrs overriding style attrs) being preserved for conditional styles also.

 

Of course, I understand that this might be contrary to what many expect. The paradigm is that when you use a conditional style, the basic style attributes have to be declared at style level and not at element level.

 

We'll have to discuss with Giulio what is the best way to use conditional styles with iReport.

 

Regards,

Lucian

 

 

By: C-Box - c-box

RE: Can't get conditionalStyle to work

2006-03-02 08:14

Okay... now I understand the styles logic a bit better!

 

So I would suggest following for iReport (perhaps I should post it in Giulios forum!?!? :-)):

 

1.) CREATING A NEW REPORT-ELEMENT

 

if there is NO Default-Style within the report, then create a new ReportElement with the current standard attributes... but if there exists a default style, then don't set the report-element attributes but therefore link the default-style to this report-element.

 

2.) SETTING A STYLE TO A EXISTING REPORT-ELEMENT

 

link the style to the report-element and delete the report-element-attributes that are NOT DEFAULT within the linked Style.

 

 

Now the problem seems to be, that Guilio always set the attributes and JR preferes these report-element attributes against the linked style. That's why my testreport doesn't work after I store the report within iReport.

 

Would be great, if you could talk to Giulio!

 

thanks for your time

C-Box

 

 

By: Lucian Chirita - lucianc

RE: Can't get conditionalStyle to work

2006-03-02 03:05

Hi

 

I stumbled upon the same problem myself when I tryed iReport 1.2.0.

 

The report element's forecolor always overrides the forecolor produced by the (conditional) style. If you remove the forecolor attribute of the text element, the conditional style would take effect.

 

I think there is an issue in iReport in that it always writes the forecolor attribute for all report elements..

 

Regards,

Lucian

 

 

By: Giulio Toffoli - gt78

RE: Can't get conditionalStyle to work

2006-03-02 09:54

Yes, I confirm this problem. It's a more general problem: iReport is not yet able to deal with "undefined" values for element properties. This is a problem when you use a conditional style because the element properties values are overridden by the emelent itself. I'll try to modify this thing leaving "undefined" not-defined properties, and to add the ability to "reset to default" some values when changed (like the foreground color).

 

Giulio

Link to comment
Share on other sites

  • 10 months later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi Giulio,

Are there plans to make the border and padding attributes undefined by default, as well as adding the little reset button for these? Right now iReport (v2) doesn't let styles - including conditional styles - set these properties because they have 'set' values.

 

Thanks!

Link to comment
Share on other sites

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...