2005 IR Help Posted August 26, 2006 Share Posted August 26, 2006 By: sven-loe - sven-loe How can I access values in a Bean? 2004-06-03 02:47 Hello, I need to internationalize my reports and have to use a bean with the right words in it. So I put the bean in the parameters and try to access it. My problem is that I can not access the values inside my bean!!! I have tried this: <textField isBlankWhenNull="true"> <reportElement x="0" y="40" width="50" height="15"/> <textElement textAlignment="Left"> <font reportFont="Arial_Bold"/> </textElement> <textFieldExpression class="java.lang.String"> <![CDATA[$P{LangBean}.getKontrakt_Id()]]> </textFieldExpression> </textField> But I allways get this error: C:eclipseworkspaceReportGeneratorUmsaetze_FX_Termin.java:184: ')' expected value = (java.lang.String)($P!{LangBean}.getKontrakt_Id()); Please help because I really need this feature. Greetings Sven By: Lucian Comanescu - lucicom RE: How can I access values in a Bean? 2004-06-03 04:00 Hi! Remove the "!" from value = $P!{LangBean}.getKontrakt_Id(). The "!" has special meaning for query ... see manual. Lucian. By: sven-loe - sven-loe RE: How can I access values in a Bean? 2004-06-03 05:07 Hello, I have removed the "!" from my .xml file. I just put in the wrong error message. Thank you for your response. This is the right one: C:eclipseworkspaceReportGeneratorUmsaetze_FX_Termin.java:184: cannot resolve symbol symbol : method getKontrakt_Id () location: class java.lang.Object value = (java.lang.String)(((java.lang.Object)parameter_LangBean.getValue()).getKontrakt_Id()); I really need a solution for the problem because it is a requirement. Thank you. Sven By: Chuck Deal - cdeal RE: How can I access values in a Bean? 2004-06-03 06:45 You have got your class types all out of whack. First, you need to identify what class you really want to be using (String, Object, your own bean class?). Second, you need to get the Parameter class type and the TextField class type in sync with each other (the same value for the class parameter). By: Lucian Comanescu - lucicom RE: How can I access values in a Bean? 2004-06-03 07:44 It looks like you've declared your parameter as java.lang.Object. Check that you have the right class (fully qualified name) when you declare the parameter: <parameter name="ReportTitle" class="<your-fully-qualified-class-name"/> Also check that you've set this parameter. parameters.put("LangBean", new LangBean("Working")); I created a simple LangBean with just a "status" field and I've modified the DataSourceReport sample ... and it is working. You have the template attached. Lucian. <?xml version="1.0" encoding="UTF-8"?> <!-- Created using JasperAssistant (http://www.jasperassistant.com) --> <!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd"> <jasperReport name="LanguageBeanReport" pageWidth="595" pageHeight="842" columnWidth="515" leftMargin="40" rightMargin="40" topMargin="50" bottomMargin="50"> <reportFont name="Arial_Normal" isDefault="true" fontName="Arial" size="12" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/> <reportFont name="Arial_Bold" isDefault="false" fontName="Arial" size="12" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Bold" pdfEncoding="Cp1252" isPdfEmbedded="false"/> <reportFont name="Arial_Italic" isDefault="false" fontName="Arial" size="12" isBold="false" isItalic="true" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Oblique" pdfEncoding="Cp1252" isPdfEmbedded="false"/> <parameter name="ReportTitle" class="java.lang.String"> </parameter> <parameter name="LangBean" class="my.tests.jasper.LangBean"></parameter> <parameter name="DataFile" class="java.lang.String"> </parameter> <field name="Id" class="java.lang.Integer"> </field> <field name="Name" class="java.lang.String"> </field> <field name="Street" class="java.lang.String"> </field> <field name="City" class="java.lang.String"> </field> <variable name="CityNumber" class="java.lang.Integer" resetType="Group" resetGroup="CityGroup" calculation="System"> <initialValueExpression><![CDATA[($V{CityNumber} != null)?(new Integer($V{CityNumber}.intValue() + 1)):(new Integer(1))]]></initialValueExpression> </variable> <group name="CityGroup" minHeightToStartNewPage="60"> <groupExpression><![CDATA[$F{City}]]></groupExpression> <groupHeader> <band height="20"> <rectangle> <reportElement x="0" y="4" width="515" height="15" forecolor="#c0c0c0" backcolor="#c0c0c0"/> <graphicElement/> </rectangle> <textField> <reportElement mode="Opaque" x="0" y="4" width="515" height="15" backcolor="#c0c0c0"/> <textElement> <font reportFont="Arial_Bold"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[" " + String.valueOf($V{CityNumber}) + ". " + String.valueOf($F{City})]]></textFieldExpression> </textField> <line> <reportElement x="0" y="19" width="515" height="1"/> <graphicElement/> </line> </band> </groupHeader> <groupFooter> <band height="20"> <line> <reportElement x="0" y="-1" width="515" height="1"/> <graphicElement/> </line> <staticText> <reportElement x="400" y="1" width="60" height="15"/> <textElement textAlignment="Right"> <font reportFont="Arial_Bold"/> </textElement> <text><![CDATA[Count :]]></text> </staticText> <textField> <reportElement x="460" y="1" width="30" height="15"/> <textElement textAlignment="Right"> <font reportFont="Arial_Bold"/> </textElement> <textFieldExpression class="java.lang.Integer"><![CDATA[$V{CityGroup_COUNT}]]></textFieldExpression> </textField> </band> </groupFooter> </group> <title> <band height="70"> <line> <reportElement x="0" y="0" width="515" height="1"/> <graphicElement/> </line> <textField isBlankWhenNull="true"> <reportElement x="0" y="10" width="515" height="30"/> <textElement textAlignment="Center"> <font reportFont="Arial_Normal" size="22"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$P{ReportTitle}]]></textFieldExpression> </textField> <textField isBlankWhenNull="true"> <reportElement x="0" y="40" width="515" height="20"/> <textElement textAlignment="Center"> <font reportFont="Arial_Normal" size="14"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$P{LangBean}.getStatus()]]></textFieldExpression> </textField> </band> </title> <pageHeader> <band height="20"> <rectangle> <reportElement x="0" y="5" width="515" height="15" forecolor="#333333" backcolor="#333333"/> <graphicElement/> </rectangle> <staticText> <reportElement mode="Opaque" x="0" y="5" width="55" height="15" forecolor="#ffffff" backcolor="#333333"/> <textElement textAlignment="Center"> <font reportFont="Arial_Bold"/> </textElement> <text><![CDATA[iD]]></text> </staticText> <staticText> <reportElement mode="Opaque" x="55" y="5" width="205" height="15" forecolor="#ffffff" backcolor="#333333"/> <textElement> <font reportFont="Arial_Bold"/> </textElement> <text><![CDATA[Name]]></text> </staticText> <staticText> <reportElement mode="Opaque" x="260" y="5" width="255" height="15" forecolor="#ffffff" backcolor="#333333"/> <textElement> <font reportFont="Arial_Bold"/> </textElement> <text><![CDATA[street]]></text> </staticText> </band> </pageHeader> <detail> <band height="20"> <textField> <reportElement x="0" y="4" width="50" height="15"/> <textElement textAlignment="Right"/> <textFieldExpression class="java.lang.Integer"><![CDATA[$F{Id}]]></textFieldExpression> </textField> <textField isStretchWithOverflow="true"> <reportElement positionType="Float" x="55" y="4" width="200" height="15"/> <textElement/> <textFieldExpression class="java.lang.String"><![CDATA[$F{Name}]]></textFieldExpression> </textField> <textField isStretchWithOverflow="true"> <reportElement positionType="Float" x="260" y="4" width="255" height="15"/> <textElement/> <textFieldExpression class="java.lang.String"><![CDATA[$F{Street}]]></textFieldExpression> </textField> <line> <reportElement positionType="Float" x="0" y="19" width="515" height="1" forecolor="#808080"/> <graphicElement/> </line> </band> </detail> <pageFooter> <band height="40"> <line> <reportElement x="0" y="10" width="515" height="1"/> <graphicElement/> </line> <textField> <reportElement x="200" y="20" width="80" height="15"/> <textElement textAlignment="Right"/> <textFieldExpression class="java.lang.String"><![CDATA["Page " + String.valueOf($V{PAGE_NUMBER}) + " of"]]></textFieldExpression> </textField> <textField evaluationTime="Report"> <reportElement x="280" y="20" width="75" height="15"/> <textElement/> <textFieldExpression class="java.lang.String"><![CDATA[" " + String.valueOf($V{PAGE_NUMBER})]]></textFieldExpression> </textField> </band> </pageFooter> <summary> <band height="60"> <textField isStretchWithOverflow="true"> <reportElement x="175" y="20" width="165" height="15"/> <textElement textAlignment="Center"> <font reportFont="Arial_Italic"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA["There were " + String.valueOf($V{REPORT_COUNT}) + " address records on this report."]]></textFieldExpression> </textField> </band> </summary> </jasperReport> By: sven-loe - sven-loe RE: How can I access values in a Bean? 2004-06-03 07:58 Hello, the idea with the types was the right one. To make the bean work 2 steps are nessecary: 1. The class type was the problem. <parameter name="LangBean" class="reports.LangBean"/> 2. This prints the value. <textField isBlankWhenNull="true"> <reportElement x="0" y="40" width="50" height="15"/> <textElement textAlignment="Left"> <font reportFont="Arial_Bold"/> </textElement> <textFieldExpression class="java.lang.String"> <![CDATA[$P{LangBean}.getKontrakt_Id()]]> </textFieldExpression> </textField> Thank you very much. Now all my imediate problems are solved and I can use Jasperreports. Greetings Sven 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