jslater Posted February 17, 2010 Share Posted February 17, 2010 Any help would be much appreciated.My requirement is the following:I have a database field that needs to change colour depending on the string it contains, that is 'Likely Cause' it should display in Red 'Possible Cause' it should display in Amber 'Unlikely Cause' it should display in GreenAs can been seen in the code I have used a conditional style, named 'AlternativeStyle'. This style has then been associated with the 'style' property of the specifc database field.Unfortunately it is not working.Please could someone point out where I am going wrong.Thanks in advance.RegardsJohn Code: <style name="AlternativeStyle" isDefault="false" mode="Opaque"> <conditionalStyle> <conditionExpression><![CDATA[new Boolean ($F{DiagnosticView_Status}.matches("Likely Cause"))]]></conditionExpression> <style isDefault="false" style="AlternativeStyle" mode="Opaque" backcolor="#00FF00"/> </conditionalStyle> <conditionalStyle> <conditionExpression><![CDATA[new Boolean ($F{DiagnosticView_Status}.matches("Possible Cause"))]]></conditionExpression> <style isDefault="false" style="AlternativeStyle" mode="Opaque" backcolor="#FF9900"/> </conditionalStyle> <conditionalStyle> <conditionExpression><![CDATA[new Boolean ($F{DiagnosticView_Status}.matches("Impossible Cause"))]]></conditionExpression> <style isDefault="false" style="AlternativeStyle" mode="Opaque" backcolor="#FF6600"/> </conditionalStyle> </style> Link to comment Share on other sites More sharing options...
Gaby38 Posted February 17, 2010 Share Posted February 17, 2010 I have several reports using conditional style that work well. In these reports, the "opaque" property is not set in the style definition but in the database textfield definition.To be more precise, as I have several fields , they are put inside a frame, and that is the frame which as the conditionnal style and the opaque property.Hope this Helps. Link to comment Share on other sites More sharing options...
jslater Posted February 17, 2010 Author Share Posted February 17, 2010 Hi Gaby38Removed the Opaque from the Style and maintain on database field. No success :-(Am I missing something else, am stumped as there is nothing more I can think off :-(ThanksJohn Link to comment Share on other sites More sharing options...
slow Posted February 18, 2010 Share Posted February 18, 2010 it works on my test...can you past all the jrxml code that concerns $F{DiagnosticView_Status} field? Link to comment Share on other sites More sharing options...
jslater Posted February 18, 2010 Author Share Posted February 18, 2010 SlowThank you for your reply. I am really getting fustrated with the issue. :-(As requested, I have pasted the code as it currently exists for the reportHowever, I have managed to get the colours working with an integer variable.So I can only assume that there maybe an issue with the condition expression statements, e.g. am I using the correct class 'equals', I really dunno?Your help will be very much appreciatedThanksJohnCode:<?xml version="1.0" encoding="UTF-8"?><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report name" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20"> <style name="AlternativeStyle" isDefault="false" backcolor="#FF0000"> <conditionalStyle> <conditionExpression><![CDATA[new Boolean ($F{DiagnosticView_Status}.equals( "Possible Cause" ))]]></conditionExpression> <style isDefault="false" style="AlternativeStyle" mode="Transparent" backcolor="#FF0000"/> </conditionalStyle> <conditionalStyle> <conditionExpression><![CDATA[new Boolean ($F{DiagnosticView_Status}.equals( "Impossible Cause" ))]]></conditionExpression> <style isDefault="false" style="AlternativeStyle" mode="Transparent" backcolor="#00FF00"/> </conditionalStyle> <conditionalStyle> <conditionExpression><![CDATA[new Boolean ($F{DiagnosticView_Status}.equals( "Unlikely Cause" ))]]></conditionExpression> <style isDefault="false" style="AlternativeStyle" mode="Transparent" backcolor="#FFC800"/> </conditionalStyle> </style> <queryString> <![CDATA[sELECT DiagnosticView."WhenChanged" AS DiagnosticView_WhenChanged, DiagnosticView."TransactionID" AS DiagnosticView_TransactionID, DiagnosticView."Status" AS DiagnosticView_Status, DiagnosticView."Date" AS DiagnosticView_Date, DiagnosticView."Time" AS DiagnosticView_Time, DiagnosticView."ObjectType" AS DiagnosticView_ObjectType, DiagnosticView."Action" AS DiagnosticView_Action, DiagnosticView."ObjectName" AS DiagnosticView_ObjectName, DiagnosticView."ChangedBy" AS DiagnosticView_ChangedBy, DiagnosticView."FromApp" AS DiagnosticView_FromAppFROM "dbo"."DiagnosticView" DiagnosticView]]> </queryString> <field name="DiagnosticView_WhenChanged" class="java.lang.Integer"> <fieldDescription><![CDATA[]]></fieldDescription> </field> <field name="DiagnosticView_TransactionID" class="java.lang.String"> <fieldDescription><![CDATA[]]></fieldDescription> </field> <field name="DiagnosticView_Status" class="java.lang.String"> <fieldDescription><![CDATA[]]></fieldDescription> </field> <field name="DiagnosticView_Date" class="java.lang.String"> <fieldDescription><![CDATA[]]></fieldDescription> </field> <field name="DiagnosticView_Time" class="java.lang.String"> <fieldDescription><![CDATA[]]></fieldDescription> </field> <field name="DiagnosticView_ObjectType" class="java.lang.String"> <fieldDescription><![CDATA[]]></fieldDescription> </field> <field name="DiagnosticView_Action" class="java.lang.String"> <fieldDescription><![CDATA[]]></fieldDescription> </field> <field name="DiagnosticView_ObjectName" class="java.lang.String"> <fieldDescription><![CDATA[]]></fieldDescription> </field> <field name="DiagnosticView_ChangedBy" class="java.lang.String"> <fieldDescription><![CDATA[]]></fieldDescription> </field> <field name="DiagnosticView_FromApp" class="java.lang.String"> <fieldDescription><![CDATA[]]></fieldDescription> </field> <group name="Status"> <groupExpression><![CDATA[$F{DiagnosticView_Status}]]></groupExpression> <groupHeader> <band height="47"> <textField> <reportElement mode="Opaque" x="397" y="12" width="100" height="12" backcolor="#EAF1DD"/> <box> <pen lineWidth="0.25"/> <topPen lineWidth="0.25"/> <leftPen lineWidth="0.25"/> <bottomPen lineWidth="0.25"/> <rightPen lineWidth="0.25"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle"> <font fontName="Arial" size="9" isBold="false"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA["Action"]]></textFieldExpression> </textField> <textField> <reportElement mode="Opaque" x="197" y="12" width="100" height="12" backcolor="#EAF1DD"/> <box> <pen lineWidth="0.25"/> <topPen lineWidth="0.25"/> <leftPen lineWidth="0.25"/> <bottomPen lineWidth="0.25"/> <rightPen lineWidth="0.25"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle"> <font fontName="Arial" size="9" isBold="false"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA["Time"]]></textFieldExpression> </textField> <textField> <reportElement mode="Opaque" x="597" y="12" width="100" height="12" backcolor="#EAF1DD"/> <box> <pen lineWidth="0.25"/> <topPen lineWidth="0.25"/> <leftPen lineWidth="0.25"/> <bottomPen lineWidth="0.25"/> <rightPen lineWidth="0.25"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle"> <font fontName="Arial" size="9" isBold="false"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA["Changed By"]]></textFieldExpression> </textField> <textField> <reportElement mode="Opaque" x="297" y="12" width="100" height="12" backcolor="#EAF1DD"/> <box> <pen lineWidth="0.25"/> <topPen lineWidth="0.25"/> <leftPen lineWidth="0.25"/> <bottomPen lineWidth="0.25"/> <rightPen lineWidth="0.25"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle"> <font fontName="Arial" size="9" isBold="false"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA["Object Type"]]></textFieldExpression> </textField> <textField> <reportElement mode="Opaque" x="697" y="12" width="100" height="12" backcolor="#EAF1DD"/> <box> <pen lineWidth="0.25"/> <topPen lineWidth="0.25"/> <leftPen lineWidth="0.25"/> <bottomPen lineWidth="0.25"/> <rightPen lineWidth="0.25"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle"> <font fontName="Arial" size="9" isBold="false"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA["From Application"]]></textFieldExpression> </textField> <textField> <reportElement mode="Opaque" x="97" y="12" width="100" height="12" backcolor="#EAF1DD"/> <box> <pen lineWidth="0.25"/> <topPen lineWidth="0.25"/> <leftPen lineWidth="0.25"/> <bottomPen lineWidth="0.25"/> <rightPen lineWidth="0.25"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle"> <font fontName="Arial" size="9" isBold="false"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA["Date"]]></textFieldExpression> </textField> <textField> <reportElement mode="Opaque" x="497" y="12" width="100" height="12" backcolor="#EAF1DD"/> <box> <pen lineWidth="0.25"/> <topPen lineWidth="0.25"/> <leftPen lineWidth="0.25"/> <bottomPen lineWidth="0.25"/> <rightPen lineWidth="0.25"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle"> <font fontName="Arial" size="9" isBold="false"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA["Object Name"]]></textFieldExpression> </textField> <textField pattern=""> <reportElement style="AlternativeStyle" mode="Opaque" x="0" y="0" width="802" height="12" backcolor="#D7E4BC"/> <textElement textAlignment="Center"> <font fontName="Arial" size="9" isBold="true" isUnderline="false"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$F{DiagnosticView_Status}]]></textFieldExpression> </textField> <textField> <reportElement x="197" y="24" width="100" height="12"/> <textElement> <font fontName="Arial" size="9"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$F{DiagnosticView_Time}]]></textFieldExpression> </textField> <textField> <reportElement x="297" y="24" width="100" height="12"/> <textElement> <font fontName="Arial" size="9"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$F{DiagnosticView_ObjectType}]]></textFieldExpression> </textField> <textField> <reportElement x="397" y="24" width="100" height="12"/> <textElement> <font fontName="Arial" size="9"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$F{DiagnosticView_Action}]]></textFieldExpression> </textField> <textField> <reportElement x="497" y="24" width="100" height="12"/> <textElement> <font fontName="Arial" size="9"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$F{DiagnosticView_ObjectName}]]></textFieldExpression> </textField> <textField> <reportElement x="597" y="24" width="100" height="12"/> <textElement> <font fontName="Arial" size="9"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$F{DiagnosticView_ChangedBy}]]></textFieldExpression> </textField> <textField> <reportElement x="697" y="24" width="100" height="12"/> <textElement> <font fontName="Arial" size="9"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$F{DiagnosticView_FromApp}]]></textFieldExpression> </textField> <textField> <reportElement mode="Opaque" x="97" y="12" width="100" height="12" backcolor="#EAF1DD"/> <box> <pen lineWidth="0.25"/> <topPen lineWidth="0.25"/> <leftPen lineWidth="0.25"/> <bottomPen lineWidth="0.25"/> <rightPen lineWidth="0.25"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle"> <font fontName="Arial" size="9" isBold="false"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA["Date"]]></textFieldExpression> </textField> <textField> <reportElement mode="Opaque" x="0" y="12" width="100" height="12" backcolor="#EAF1DD"/> <box> <pen lineWidth="0.25"/> <topPen lineWidth="0.25"/> <leftPen lineWidth="0.25"/> <bottomPen lineWidth="0.25"/> <rightPen lineWidth="0.25"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle"> <font fontName="Arial" size="9" isBold="false"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA["TranID"]]></textFieldExpression> </textField> <textField> <reportElement x="0" y="24" width="100" height="12"/> <textElement> <font fontName="Arial" size="9"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$F{DiagnosticView_TransactionID}]]></textFieldExpression> </textField> <textField> <reportElement x="100" y="24" width="100" height="12"/> <textElement> <font fontName="Arial" size="9"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$F{DiagnosticView_Date}]]></textFieldExpression> </textField> </band> </groupHeader> <groupFooter> <band height="23"/> </groupFooter> </group> <background> <band/> </background> <title> <band/> </title> <pageHeader> <band height="15"> <staticText> <reportElement mode="Opaque" x="545" y="2" width="255" height="12" backcolor="#EAF1DD"/> <textElement textAlignment="Right"> <font fontName="Arial" size="9" isBold="false"/> </textElement> <text><![CDATA[Diagnostic Report for Purple Telecom]]></text> </staticText> <textField> <reportElement mode="Opaque" x="0" y="2" width="547" height="12" backcolor="#EAF1DD"/> <textElement> <font fontName="Arial" size="9"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA["Activity in Genesys CME "]]></textFieldExpression> </textField> </band> </pageHeader> <columnHeader> <band/> </columnHeader> <detail> <band/> </detail> <columnFooter> <band/> </columnFooter> <pageFooter> <band/> </pageFooter> <summary> <band/> </summary></jasperReport> Link to comment Share on other sites More sharing options...
slow Posted February 18, 2010 Share Posted February 18, 2010 the best method for the test you make is FIELDNAME.equals("something") because you pass to the method a simple string ad not a regular expression... but that isn't a error... the code you past seem to be correct...try to use something like this in your rule:new Boolean ($F{DiagnosticView_Status}.toUpperCase().equals( "...something...".toUpperCase() ))(the test is case sensitive...!)if numbers (integers?) avoid the issue, another way to solce it is to code the string from the db in a number code and then set in the rule you specify the correct number. Link to comment Share on other sites More sharing options...
jslater Posted February 21, 2010 Author Share Posted February 21, 2010 Hi AllThanks to all for your help.Finally resolved the issue by creating another database field with the integer equivalent of the specfic text that was expected to control the field colour, that is'Likely Cause' = 1 and should display in Red'Possible Cause' = 2 and should display in Amber'Unlikely Cause' = 3 and should display in GreenThis new field was then used in the condition expression rather than the text field. This worked perfectly.I hope this helps someone else with a similar requirement, Thank you once again to all those who helped.CheersJohn Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now